doupiai5597 2017-02-16 04:40
浏览 36

twitter发布视频使用chanked api使用php无效

hear is my code it's showing me error when i am uploading video on twitter

<?php
    $video = 'images/video1.mp4'; /// video size is 2 mb and it's time duration around 20 seconeds
    $code = $twitter->upload('media/upload',
                             ["command" => "INIT",
                              "total_bytes" => (int)filesize($video),
                              'media_type' => 'video/mp4']
                            );
    var_dump($code);
    $video_media_id = $code->media_id_string;
    $fp = fopen($video, 'r');
    $segment_id = 0;
    while (! feof($fp)) {
        $chunk = fread($fp, 1048576); // 1MB per chunk for this sample
        $twitter->upload('media/upload',
                         ["command" => "APPEND",
                          "media_id" => $video_media_id,
                          "media_data" => base64_encode($chunk),
                          "segment_index" => $segment_id]
                        );
        $segment_id++;
    }
    $final=$twitter->upload('media/upload',
                            ["command" => "FINALIZE",
                             "media_id" => $video_media_id]
                           );
    var_dump($final);
    $parameters = [
        'status' => 'hear is my video twittsvbn',
        'media_id' => $video_media_id
    ];
    print_r($parameters);
    $tweet=  $twitter->post('statuses/update',  $parameters);
    echo json_encode($tweet); 
    ?>

it was showing me error object(stdClass)#933 (2) { ["request"]=> string(22) "/1.1/media/upload.json" ["error"]=> string(51) "Segments do not add up to provided total file size." }

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测