0

I am using codebird for uploading video .

status text is displaying in twitter account but it is not uploading/showing video .

here is twitter response.

1470928 byte object(stdClass)#7 (3) { ["errors"]=> array(1) { [0]=> object(stdClass)#6 (2) { ["code"]=> int(324) ["message"]=> string(35) "Invalid media id 806853054318448640" } } ["httpstatus"]=> int(400) ["rate"]=> NULL }

and Code

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

$cb = \Codebird\Codebird::getInstance();

$cb->setToken('Xyz', 'xyz');
  $file       = 'www.something.com/*.mp4';
  $size_bytes = filesize($file);

$ch = curl_init($file);
  curl_setopt($ch, CURLOPT_NOBODY, true);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HEADER, true);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

  $data = curl_exec($ch);
  curl_close($ch);
  echo '<br>';
  if (preg_match('/Content-Length: (\d+)/', $data, $matches)) {

      // Contains file size in bytes
      $contentLength = (int)$matches[1];

  }

echo  $size_bytes = $contentLength ;

$fp  = fopen($file, 'r');

// INIT the upload

$reply = $cb->media_upload([
  'command'     => 'INIT',
  'media_type'  => 'video/mp4',
  'total_bytes' => $size_bytes
]);
       $media_id = $reply->media_id_string;
 $media_id ;

$segment_id = 0;

while (! feof($fp)) {
  $chunk = fread($fp, 1048576); // 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);

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


if ($reply->httpstatus < 200 || $reply->httpstatus > 299) {
  die();
}

$reply2 = $cb->statuses_update([
  'status'    => 'Tw gvifdeggeo uploadsrrs.',
  'media_ids' => $media_id
]);

var_dump($reply2);

Curl and allow_url_fopen are enabled Help me what i am missing ? or what this reponse indicates ?

  • why does the code snippet start with `$media_id = $reply->media_id_string;`? please post the entire relevant code (and how you got `$reply` in this case is highly relevant – WEBjuju Dec 08 '16 at 12:37

1 Answers1

0

After getting the media_id, you have successfully uploaded the media to your account. The next step is to tweet using that media. Here is a snippet example:

//upload the file to your twitter account
$mediaID = $reply->media_id_string;

//build the data needed to send to twitter, including the tweet and the image id
$params = array(
  'status' => $message,
  'media_ids' => $mediaID   // BE SURE TO TWITTER's NOT YOURS!
);
//post the tweet with codebird
$reply2 = $cb->statuses_update($params);

dump out the 2nd reply

var_dump($reply2);

This snippet is taken from Stack Overflow with answer explaining how to tweet using an image as the media.

Community
  • 1
  • 1
WEBjuju
  • 5,797
  • 4
  • 27
  • 36
  • please move your `var_dump` - let's see the *2nd* `$reply` after posting the tweet. – WEBjuju Dec 08 '16 at 12:23
  • ah, i see the issue - you are using *your* `$media_id` and should be using the *Twitter* `$reply->media_id_string`; **also** `statuses_update()` requires a parameter called `media_ids` with an *s*. You must update that as well since you are sending `media_id` without the *s*. – WEBjuju Dec 08 '16 at 12:28
  • object(stdClass)#4 (25) { ["created_at"]=> string(30) "Thu Dec 08 12:30:12 +0000 2016" ["id"]=> int(806838285167427584) ["id_str"]=> string(18) "806838285167427584" ["text"]=> string(20) "Tw video uploadsrrs." ["truncated"]=> bool(false) ["entities"]=> object(stdClass)#5 (4) { ["hashtags"]=> array(0) { } ["symbols"]=> array(0) { } ["user_mentions"]=> array(0) { } ["urls"]=> array(0) { } } ["source"]=> string(60) "dadlapi.com" ["in_reply_to_status_id"]=> NULL ["in_reply_to_status_id_str"]=> NULL ["in_reply_to_user_id"]=> NULL ["in_reply_to_user_id_str"]=> NULL after this profile info.. – user1846871 Dec 08 '16 at 12:34
  • did you update the parameter to `media_ids`. please update your post and don't put the updates in comments. – WEBjuju Dec 08 '16 at 12:36
  • update your code in the example. note: i still don't understand why your code starts with a line indicating you already have a response reply from Twitter. – WEBjuju Dec 08 '16 at 13:35
  • no you should just replace personal/secret information with xxxxxx – WEBjuju Dec 08 '16 at 14:06
  • video length should less than 30 sec and should be MP4 1280*720 H.264 AAC like format more info on twitter developer page – user1846871 Dec 09 '16 at 10:45