twitter rest api在上传时给我一个错误的媒体ID

时间:2017-09-16 11:10:31

标签: php twitter upload twitter-rest-api

我创建了一个用于在Twitter上传媒体(图像/视频)的PHP脚本。

它工作正常但是Twitter api在上传后给了我一个错误的媒体ID。 这就是api给我的:image

但在Twitter中,上传的媒体有不同的ID:image

require_once ('codebird/src/codebird.php');
\Codebird\Codebird::setConsumerKey('nTfFKquXujBPDtwTgdVNxNUtN', 
'mvjcHYw0gPvF6FyGXyef7cg3W2MACrfIJPC9DN5eNWG6aqXt01'); // static, see README

$cb = \Codebird\Codebird::getInstance();
$cb->setToken('894836445751513088-kpp4ZVkHYNQEMlrdFqc05bdQKSGVkZc', 
'Erji4c37RV3xru4pBfPaUqV5t33i7gEo37RUND5cDbf1O');
require "../connexion.php";
$row=$video->getVideobyid($PDO,$_GET['id']);
print_r($row);

$file       ='../../upload/'.$row[0]->path;
$size_bytes = filesize($file);
$fp         = fopen($file, 'rb');

// INIT the upload

$reply = $cb->media_upload([
'command'     => 'INIT',
'media_type'  => 'video/'.$row[0]->type,
'total_bytes' => $size_bytes
 ]);

 $media_id = $reply->media_id_string;

 // APPEND data to the upload

 $segment_id = 0;

 while (! feof($fp)) {set_time_limit(900000000000000000000);
 $chunk = fread($fp, 13421772); // 1MB per chunk for this sample

 $reply = $cb->media_upload([
'command'       => 'APPEND',
'media_id'      => $media_id,
'segment_index' => $segment_id,
'media'         => $chunk
 ]);

 $segment_id++;
 }

 fclose($fp);

 // FINALIZE the upload

 $reply = $cb->media_upload([
 'command'       => 'FINALIZE',
 'media_id'      => $media_id
  ]);
  var_dump($cb);
  var_dump($reply);

  if ($reply->httpstatus < 200 || $reply->httpstatus > 299) {
  print("now exiting because httpstatus");
  die();
  }

  // if you have a field `processing_info` in the reply,
  // use the STATUS command to check if the video has finished processing.

 // Now use the media_id in a Tweet
 $reply = $cb->statuses_update([
 'status'    => $row[0]->titre,
 'media_ids' => $media_id
 ]);

任何解决方案或解释?

0 个答案:

没有答案