Upload image in twitter using twitter api in php

Discussion in 'Twitter' started by dineshsingh1984, Jun 6, 2015.

  1. #1
    hello,
    I'm using below script for upload image but this script is not work for image uploading.

    ************************************************
    <?php
    require_once('TwitterOAuth.php');
    include 'EpiTwitter/EpiCurl.php';
    include 'EpiTwitter/EpiOAuth.php';
    include 'EpiTwitter/EpiTwitter.php';
    include 'EpiTwitter/TwitterConfig.php';
    include("db.php");
    ?>
    <form action="" method="post" enctype="multipart/form-data">
    <input type="text" name="post_name" value="" />
    <input type="file" name="post_image" />
    <input type="submit" name="send" />
    </form>
    <?php
    if(isset($_POST['post_name']) && !empty($_SESSION['TwitterUsername']))
    {
    $message=$_POST['post_name'];
    $TwitterUsername=$_SESSION['TwitterUsername'];
    $tw_sql=mysqli_query($connection,"SELECT oauth_token,oauth_token_secret FROM TwitterUpdate WHERE uname='$TwitterUsername'");
    $row=mysqli_fetch_array($tw_sql,MYSQLI_ASSOC);
    $oauth_token=$_SESSION['oauth_token'];
    $oauth_token_secret=$_SESSION['oauth_token_secret'];
    if(strlen($oauth_token)>0 && strlen($oauth_token_secret)>0 )
    {
    $Twitter = new EpiTwitter($consumer_key, $consumer_secret);
    $Twitter->setToken($oauth_token,$oauth_token_secret);


    $status=$Twitter->post_statusesUpdate(array('status' => $message));

    $image = 'http://www.bitrebels.com/wp-content/uploads/2013/05/3d-printed-rose-geek-1.jpg';
    $response = $Twitter->request('POST', $Twitter->url('https://upload.twitter.com/1/statuses/update_with_media'),
    array(
    'status' => $message,
    'media[]' => "@{$image}"
    ));
    echo $status->id_str;
    }
    }
    ?>
    **********************************************
    plz tell me where the problem my message is posts successfully but image is not upload....

    please help

    thanks
     
    dineshsingh1984, Jun 6, 2015 IP