kalpesh kalpesh - 3 months ago 44
PHP Question

How to post tweet (description and images) in twitter using API or JAVASCRIPT

I want to post description and images using twitter API or JavaScript so what the code for that... Please help or any solution for that.

I have use the following code.

include('tmhOAuth.php');
include('tmhUtilities.php');

$tmhOAuth = new tmhOAuth(array(
'consumer_key' => '2gfF75xRSwnJDgfuwXBUGj59kA',
'consumer_secret' => 'snGgVlYdVfgOeTVl8aQYG5BQRyEbgxqfgu9B9zTpRomIUh58',
'user_token' => '148xf1479562-RYq76XIfgogfhjttdu0kLlWwQwEfgEM8wlRDMX44rUFPP',
'user_secret' => 'I7saxfu751zzMnWChgffA0VAiRQIdf2JFwTMLragf6MK4aF8pjbg',
));

$image = 'Chrysanthemum.jpg';
$code = $tmhOAuth->request('POST', 'https://upload.twitter.com/1/statuses/update_with_media.json',
array(
'media[]' => "@{$image}",
"status" => "Is this working now?"
),
true, // use auth
true // multipart
);
if ($code == 200) {
tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
} else {
tmhUtilities::pr($tmhOAuth->response['response']);
}


But , i have got this error:
JSON RESPONSE:

{
errors: [
{
message: "The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.",
code: 68
}
]
}

Answer

I guess you should use the 1.1 API http://dev.twitter.com/blog/api-v1-is-retired

https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media

Resource URL
https://api.twitter.com/1.1/statuses/update_with_media.json
Comments