0

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

它工作正常,但 twitter api 在上传后给我一个错误的媒体 ID。这就是 api 给我的:图像

但在 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
 ]);

任何解决方案或解释?

4

0 回答 0