通过状态/ update_with_media发布多张图片来自亚伯拉罕的twitteroauth图书馆

时间:2015-12-30 06:17:52

标签: twitter twitter-oauth

我试图通过亚伯拉罕的twitteroauth图书馆的状态/ update_with_media twitter api发布多张图片。     我发布单张图片但没有多张图片。

My code is like below:

$params = array('media[]' => file_get_contents($image_url),
                'status' => $message
               );
$connection->post('statuses/update_with_media',$params,true);

Where $connection is a object of TwitterOAuth.

Function of TwitterOAuth library is below:

function post($url, $parameters = array(), $multipart = false) {
    $response = $this->oAuthRequest($url, 'POST', $parameters, $multipart);
    if ($this->format === 'json' && $this->decode_json) {
      return json_decode($response);
    }
    return $response;
}

我知道我必须在媒体[]中做一些改变。但是我无法获得正确的输出。 所以请建议我。

提前致谢 哈里沙阿

1 个答案:

答案 0 :(得分:0)

您可以像这样在Twitter上发布多张图片

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, 
   $access_token_secret);
$firstimage = $connection->upload('media/upload', ['media' => '/path/to/file/kabootar1.jpg']);
$secondimage = $connection->upload('media/upload', ['media' => '/path/to/file/kabootar2.jpg']);
$parameters = [
'status' => 'This is a test tweet',
'media_ids' => implode(',', [$firstimage->media_id_string, $secondimage->media_id_string])];
 $output = $connection->post('statuses/update', $parameters);
相关问题