问题
I got code changing twitter status, unfortunately it does not posting image.
Please review my code and help me posting 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";
回答1:
Seems that you should upload your 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 the docs to upload up to 4 media resources in the same tweet
And then send the tweet with the parameters.
$send_tweet = $connection->post('statuses/update', $parameters);
You can see an example using media here: https://twitteroauth.com/
And the statuses/update reference here: https://dev.twitter.com/rest/reference/post/statuses/update
回答2:
$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
来源:https://stackoverflow.com/questions/29897694/php-post-media-image-to-twitter