I want to tweet / status update with an image using php.
After I went through these https://github.com/J7mbo/twitter-api-php and https://dev.twitter.com/rest/reference/post/statuses/update_with_media ,
I tried with this following code.
<?php
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "my access token",
'oauth_access_token_secret' => "my access token secret",
'consumer_key' => "my customer key",
'consumer_secret' => "my consumer secret"
);
$twitter = new TwitterAPIExchange($settings);
$urlimage = 'https://api.twitter.com/1.1/statuses/update_with_media.json';
$image = 'http://postimg.org/image/xrmk2j24r/';
$twitterMessage = 'I am the Message';
$method='POST';
$file2upload = array(
'media' => file_get_contents($image),
'status' => $twitterMessage
);
$action = $twitter->buildOauth($urlimage, $method)
->setPostfields($file2upload)
->performRequest();
return json_decode($action);
?>
but NO status update / image upload happened using this code.
Then I found This endpoint has been DEPRECATED. Please use POST statuses/update for uploading one or more media entities in https://dev.twitter.com/rest/reference/post/statuses/update_with_media
so referred https://dev.twitter.com/rest/reference/post/statuses/update as per twitter suggested.. then that page lead to some other page.
I am quit confuse with their documentation. could not make it work.
How can I do this?
what are the changes need to be done in my code?
0 comments:
Post a Comment