【问题标题】:Post Multiple images by statuses/update_with_media twitter api of abraham's twitteroauth library通过 abraham 的 twitteroauth 库的 statuses/update_with_media twitter api 发布多张图片
【发布时间】:2015-12-30 06:17:51
【问题描述】:

我正在尝试通过 abraham 的 twitteroauth 库的 statuses/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;
}

我知道我必须对 media[] 进行一些更改。但我无法获得正确的输出。 所以请给我建议。

提前致谢 哈里·沙阿

【问题讨论】:

    标签: twitter twitter-oauth


    【解决方案1】:

    你可以像这样在推特上发布多张图片

    $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);
    

    【讨论】:

      猜你喜欢
      • 2012-05-18
      • 1970-01-01
      • 1970-01-01
      • 2012-02-28
      • 1970-01-01
      • 1970-01-01
      • 2017-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多