twitter rest api give me a wrong media id in uploading

210 views Asked by At

i create a php script for uploading media(image/video) in twitter.

it's working correctly but twitter api give me a wrong media id after uploading. this is what the api give me : image.

but in twitter the uploaded media has a different 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
 ]);

any solutions or explications ??

0

There are 0 answers