abraham / abraham/twitteroauth

Video Upload On twiter api using PHP

未关闭
#1,228 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Triage
主要语言
PHP
星标
4.3k
派生
1.7k
平均合并
4 天 19 小时
30 天内合并 PR
4

描述

```php
$video = $_FILES['videoFile']['tmp_name'];
$twitter->setApiVersion('1.1');

$code = $twitter->upload('media/upload',[
'media' => $video,
"command"=>"INIT",
'media_type' => 'video/mp4',
'media_category' => 'tweet_video',
"total_bytes" => (int)filesize($video),
]);
$twitter->setApiVersion(1.1);

$total_bytes=(int)filesize($video);
$twitter->setApiVersion('2');
$video_media_id = $code->media_id_string;
$media_id = $code->media_id;
var_dump("id".$media_id);
$fp = fopen($video, 'rb'); // Open the video file for reading
$segment_id = 0;
$bytes_sent = 0;

while ($bytes_sent < $total_bytes) {
$chunk = fread($fp, 4 * 1024 * 1024); // Read a chunk of 4MB

echo 'APPEND\n'.$total_bytes;

$request_data = [
'command' => 'APPEND',
'media_id' => $media_id,
'segment_index' => $segment_id,
"media_data" => base64_encode($chunk),
];



$response = $twitter->upload('media/upload', ['media'=>$chunk]);

$segment_id++;
$bytes_sent = ftell($fp); // Get the current position of the file pointer

// echo $bytes_sent . ' of ' . $total_bytes . ' bytes uploaded\n';
}

fclose($fp); // Close the file
echo "Upload chunks complete.\n";
$final=$twitter->upload('media/upload',
["command" => "FINALIZE",
"media_id" => $media_id]
);
var_dump($final);
echo '------------------------------------------------------
';
$parameters = [
'status' => 'hear is my video twittsvbn',
'media_id' => $media_id
];
print_r($parameters);
echo '------------------------------------------------------
';
$tweet= $twitter->post('statuses/update', $parameters);

echo json_encode($tweet);

```

Hello Guys i try to upload video to X but the above code say me Warning: Undefined array key "media" in C:\xampp\htdocs\mework\vendor\abraham\twitteroauth\src\TwitterOAuth.php on line 358

Fatal error: Uncaught TypeError: is_readable(): Argument #1 ($filename) must be of type string, null given in C:\xampp\htdocs\mework\vendor\abraham\twitteroauth\src\TwitterOAuth.php:358 Stack trace: #0 C:\xampp\htdocs\mework\vendor\abraham\twitteroauth\src\TwitterOAuth.php(358): is_readable(NULL) #1 C:\xampp\htdocs\mework\vendor\abraham\twitteroauth\src\TwitterOAuth.php(322): Abraham\TwitterOAuth\TwitterOAuth->uploadMediaNotChunked('media/upload', Array) #2 C:\xampp\htdocs\mework\index.php(65): Abraham\TwitterOAuth\TwitterOAuth->upload('media/upload', Array) #3 {main} thrown in C:\xampp\htdocs\mework\vendor\abraham\twitteroauth\src\TwitterOAuth.php on line 358

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。