小编Dea*_*con的帖子

PHP Twitter API 分块上传问题:Segments 加起来没有达到提供的总文件大小

所以我将 Twitter API 集成到一个应用程序中,我需要它能够发布图像、视频和 gif 动画。

我正在使用 php5.6 和 J7mbo/twitter-api-php 包。

到目前为止,我的代码如下:

     $file = fopen(realpath('../path/' . $row['path']), 'rb');
      $size = fstat($file)['size'];
      $mime_type = mime_content_type($row['path']);

      var_dump($size);
      var_dump($mime_type);


      $upload_url = 'https://upload.twitter.com/1.1/media/upload.json';
      $requestMethod = 'POST';

  $postfields = array(
          "command" => "INIT",
          'media_type' => $mime_type,
        //  'media_category' => 'tweet_video',
          'total_bytes' => $size
      );

      $initResult = json_decode($twitter->buildOauth($upload_url, $requestMethod)
        ->setPostfields($postfields)
        ->performRequest());


      $mediaId = $initResult->media_id_string;

      $segmentId = 0;

      while (!feof($file)) {
        $chunk = fread($file, 100000);

          echo strlen($chunk);


          $postfields = array(
              "command" => "APPEND",
              "media_id" => $mediaId,
              "segment_index" …
Run Code Online (Sandbox Code Playgroud)

php api twitter

5
推荐指数
1
解决办法
328
查看次数

标签 统计

api ×1

php ×1

twitter ×1