所以我将 Twitter API 集成到一个应用程序中,我需要它能够发布图像、视频和 gif 动画。
我正在使用 php5.6 和 J7mbo/twitter-api-php 包。
到目前为止,我的代码如下:
$file = fopen(realpath('../path/' . $row['path']), 'rb');
$size = fstat($file)['size'];
$mime_type = mime_content_type($row['path']);
var_dump($size);
var_dump($mime_type);
$upload_url = 'https://upload.twitter.com/1.1/media/upload.json';
$requestMethod = 'POST';
$postfields = array(
"command" => "INIT",
'media_type' => $mime_type,
// 'media_category' => 'tweet_video',
'total_bytes' => $size
);
$initResult = json_decode($twitter->buildOauth($upload_url, $requestMethod)
->setPostfields($postfields)
->performRequest());
$mediaId = $initResult->media_id_string;
$segmentId = 0;
while (!feof($file)) {
$chunk = fread($file, 100000);
echo strlen($chunk);
$postfields = array(
"command" => "APPEND",
"media_id" => $mediaId,
"segment_index" …Run Code Online (Sandbox Code Playgroud)