1

the below code I used for posting image to twitter but nothing happened, really post text its to easy , but posting image no , I searched but there was no correct result :

<?php



include ("OAuth.php");
include ("twitteroauth.php");
include ("tmhOAuth.php");
include ("tmhUtilities.php");


$tmhOAuth = new tmhOAuth(array(
  'consumer_key'    => 'SDKFJDKSLFJLAKSDFJLKSDJFLKSDJFKLS09RYER;',
  'consumer_secret' => 'JSDFLKDJSFLKDSJFLKJSDKLFJDLKFJKLDFJKLSDJF',
  'user_token'      => '93593-SDLKFJSDLKFJKLSDFJKLSDJFKLSDJFLKSDF',
  'user_secret'     => 'KSDJFKLSDJFR93490E90RI90WEIR90EIEIF9DIF',
));



    $image = 'image.jpg';

    $code = $tmhOAuth->request( 'POST','https://upload.twitter.com/1/statuses/update_with_media.json',
       array(
            'media[]' => "@{$image};type=image/jpg;filename={$image}",
            'status'   => 'message text written here',
       ),
        true, // use auth
        true  // multipart
    );

    if ($code == 200){
       tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
    }else{
       tmhUtilities::pr($tmhOAuth->response['response']);
    }
    return tmhUtilities;



?>

Kindly inform me if there any error , please guys I need it , thanks for any help

ROR
  • 271
  • 3
  • 29

2 Answers2

0

Your request object is setup wrong use this as an example to fix it.

$params = array(
'media[]' => "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}",
'status'  => $_POST['status']
);

 $code = $tmhOAuth->user_request(array(
'method' => 'POST',
'url' => $tmhOAuth->url("1.1/statuses/update_with_media"),
'params' => $params,
'multipart' => true
));
Sean Keane
  • 411
  • 1
  • 6
  • 19
0

update_with_media works by appending the URL of the image to the end of a Tweet. On Twitter, the image at the URL is displayed. Since URLs on Twitter are 22 characters (for HTTP) or 23 characters (for HTTPS), your status cannot be over 140-22 or 140-23 characters. Make your status less than 117 characters and try again.

If that doesn't work, then it might be a problem with the library. I recommend using CodeBird.

Leo Jiang
  • 24,497
  • 49
  • 154
  • 284