Php Twitter与媒体发布推文

Php Twitter与媒体发布推文,php,twitter,Php,Twitter,有了这段代码,我可以上传图片和打印媒体ID,但我不能发布带有图片的tweet。你能帮我吗 谢谢 <?php error_reporting(E_ALL); ini_set('display_errors', 1); set_include_path('/home/.....'); require_once('TwitterAPIExchange.php'); /** Set access tokens here - see: https://dev.twitter.com/apps/

有了这段代码,我可以上传图片和打印媒体ID,但我不能发布带有图片的tweet。你能帮我吗

谢谢

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
set_include_path('/home/.....');
require_once('TwitterAPIExchange.php');


/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
    'oauth_access_token' => "...",
    'oauth_access_token_secret' => "...",
    'consumer_key' => "...",
    'consumer_secret' => "..."
);
$twitter = new TwitterAPIExchange($settings);


$file = file_get_contents('aaa.jpg');
$data = base64_encode($file);

// Upload image to twitter
$url = "https://upload.twitter.com/1.1/media/upload.json";
$method = "POST";
$params = array(
"media_data" => $data,
);

$json = $twitter
->buildOauth($url, $method)
->setPostfields($params)
->performRequest();

// Result is a json string
$res = json_decode($json);
// Extract media id
$id = $res->media_id_string;
print_r($id);   

media_id值可用于使用status/update端点创建带有附加照片的Tweet。使用您的媒体id作为

中的参数对不起,我不能完全理解。我想我在状态/更新中使用媒体id作为参数。我必须改变什么@高瑟姆吓了一跳
$url = "https://api.twitter.com/1.1/statuses/update.json";
$twitter = new TwitterAPIExchange($settings);
$requestMethod = 'POST';
$response = $twitter->setPostfields(
    array('status' => '', 'media_ids' => $id)
)
                    ->buildOauth($url, $requestMethod)
                    ->performRequest();