PHP - Post Media / Image to twitter
I got the code to change Twitter status, unfortunately it doesn't post the image.
Read my code and help me place an image with text.
$consumerKey = '';
$consumerSecret = '';
$oAuthToken = '';
$oAuthSecret = '';
include "OAuth.php";
include "twitteroauth.php";
require_once('twitteroauth.php');
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret);
$tweet->post('statuses/update', array('status' => 'PHP --> example.co.uk <-- ', 'media[]' => "http://www.balanced-hr.com/wp- content/uploads/2014/08/majster.jpg"));
echo "your message has been sent to twitter API";
+3
source to share
2 answers
It seems like you have to load media first (after creating TwitterOAuth object)
$media = $tweet->upload('media/upload', array('media' => 'path_to_your_file'));
Then set the parameters of your tweet (like status and media)
$parameters = array(
'status' => 'Your Tweet status',
'media_ids' => $media->media_id_string);
You can view upload documents for up to 4 media resources on the same twitter
And then send a tweet with parameters.
$send_tweet = $connection->post('statuses/update', $parameters);
You can see an example using the media here: https://twitteroauth.com/
And status / update links here: https://dev.twitter.com/rest/reference/post/statuses/update
+5
source to share
$connection = new TwitterOAuth($consumerkey, $consumersecret, $access_token, $access_token_secret);
$content = $connection->get("account/verify_credentials");
check the connection first
$result = $connection->upload('media/upload', array('media' => 'Relative Path to your media'));
$mediaID = $result->media_id;
$parameters = array('status' => 'First tweet','media_ids' => $mediaID);
$response = $connection->post('statuses/update', $parameters);
The above code worked in my instance
+2
source to share