Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter api 1.1 update_with_media

Tags:

php

twitter

i'm changing my php code to be compatible with new API and i'm stuck with update_with_media. This is my code:

$image = constant('PATH_UPLOAD').$db_data['post_image'];
$connection = new TwitterOAuth(constant('CONSUMER_KEY'), constant('CONSUMER_SECRET'), $db_data['tw_oauth_token'], $db_data['tw_oauth_secret']);          
$content = $connection->OAuthRequest('https://api.twitter.com/1.1/account/verify_credentials.json', 'GET', array());
$twitterInfo = json_decode($content);                      
$resp_tw = $connection->OAuthRequest('https://api.twitter.com/1.1/statuses/update_with_media.json', 'POST', 
             array(
               'status'   => html_entity_decode($db_data['post_text'],ENT_QUOTES,'UTF-8'),              
                 'media[]'  => "@{$image}"
             )         
           );                          

And it returns

{"errors":[{"code":189,"message":"Error creating status"}]}

What might be the problem / what i'm doing wrong?

like image 885
Roob Avatar asked Jan 13 '23 03:01

Roob


1 Answers

you can try like this :

$tmhOAuth = new tmhOAuth(array(
  'consumer_key' => 'abc',
  'consumer_secret' => 'abc',
  'user_token' => 'abc',
  'user_secret' => 'abc',
));

$response = $tmhOAuth->request('POST', $tmhOAuth->url('1.1/statuses/update_with_media'),
array(
       'status' => $message,
       'media[]'  => file_get_contents($image)
));
if ($response != 200) {
    //Do something if the request was unsuccessful
}

there is my code test https://twitter.com/wallapps/status/357137553691906048

like image 181
Sendy Avatar answered Jan 21 '23 12:01

Sendy