I am using Codebird as part of a backend process to allow admins to Tweet from within their application. The code I am using executes but always seems to return "pending status" even when given a full minute to allow for Twitter processes to complete. My code is like this:
require_once('../../vendor/jublonet/codebird-php/src/codebird.php');
\Codebird\Codebird::setConsumerKey('xxxxxx', 'yyyyyy');
$cb = \Codebird\Codebird::getInstance();
$cb->setToken('zzzzzzz', 'wwwwwwwww');
$cb->setTimeout(60 * 1000); // 60 second request timeout
$video = '/home/user/domain/video_intros/Climax.mp4';
$tweet_text = “BLAH BLAH BLAH”;
$file = fopen($video, 'rb');
$size = fstat($file)['size'];
///get the id opf the media
$media = $cb->media_upload([
'command' => 'INIT',
'media_type' => 'video/mp4',
'media_category' => 'tweet_video',
'total_bytes' => $size,
]);
$mediaId = $media->media_id_string;
///append the video chunks
$segmentId = 0;
while (!feof($file)) {
$chunk = fread($file, 4 * 1024 * 1024);
$media = $cb->media_upload([
'command' => 'APPEND',
'media_id' => $mediaId,
'segment_index' => $segmentId,
'media' => $chunk,
]);
$segmentId++;
}
///finalize
fclose($file);
$media = $cb->media_upload([
'command' => 'FINALIZE',
'media_id' => $mediaId,
'media_category' => 'tweet_video',
]);
if(isset($media->processing_info)) {
$info = $media->processing_info;
if($info->state != 'succeeded') {
$attempts = 0;
$checkAfterSecs = $info->check_after_secs;
$success = false;
do {
$attempts++;
sleep($checkAfterSecs);
$media = $cb->media_upload([
'command' => 'STATUS',
'media_id' => $mediaId,
]);
$procInfo = $media->processing_info;
if($procInfo->state == 'succeeded' || $procInfo->state == 'failed') {
break;
}
$checkAfterSecs = $procInfo->check_after_secs;
} while($attempts <= 60);
}
}
$params = [
'status' => $tweet_text,
'media_ids' => $mediaId,
];
echo var_dump($params);
die();
$tweet = $cb->statuses_update($params);
T he var_dump at the end returns something like the following, indicating that status remains as "pending."
object(stdClass)#4 (8) { ["media_id"]=> int(1630558011977547777) ["media_id_string"]=> string(19) "1630558011977547777" ["media_key"]=> string(21) "7_1630558011977547777" ["size"]=> int(71485994) ["expires_after_secs"]=> int(86400) ["processing_info"]=> object(stdClass)#5 (2) { ["state"]=> string(7) "pending" ["check_after_secs"]=> int(1) } ["httpstatus"]=> int(200) ["rate"]=> object(stdClass)#6 (3) { ["limit"]=> string(3) "615" ["remaining"]=> string(3) "613" ["reset"]=> string(10) "1677593755" } }
The video in thios case is 71 MB.
It seems like there should be enough time for this process.