node.js - Twitter API POST 媒体/上传(分块)错误 "Not found"

标签 node.js api twitter

为什么当我附加分块数据时它会返回

"{"request":"/1.1/media/upload.json","error":"Not found."}" ?

FINALIZE 返回:

"{"errors":[{"message":"Sorry, that page does not exist","code":34}]}"

var CHUNK_SIZE = 1024, 
    buffer = new Buffer(CHUNK_SIZE),
    filePath = './web.mp4',
    data, segment_index,
    media = null;


async.series([
    function (callback) { 
        request.post({
            url: "https://upload.twitter.com/1.1/media/upload.json", oauth: oauth, host: "upload.twitter.com", protocol: "https:", formData: {
                command: "INIT",
                media_type: 'video/mp4',
                total_bytes: 854429
            }
        }, function requestCallback(err, res, body) {
            media = body;
            segment_index = 0;
            callback();
        });

    },
    function (callback) {
        var fd = fs.openSync(filePath, 'r');

        var nread = fs.readSync(fd, buffer, 0, CHUNK_SIZE, null);

        if (nread === 0) {
        } else {

            if (nread < CHUNK_SIZE) {
                data = buffer.slice(0, nread);
            } else {
                data = buffer;
            }

            request.post({
                url: "https://upload.twitter.com/1.1/media/upload.json", oauth: oauth, host: "upload.twitter.com", protocol: "https:", formData: {
                    command: "APPEND",
                    media_id: JSON.parse(media).media_id,
                    segment_index: segment_index,
                    media: data.toString('base64')
                },
                headers: {
                    'Content-Transfer-Encoding': 'base64'
                }
            }, function requestCallback(err, res, body) {
                if (err) {
                    throw err;
                }
            });

        }

        callback();

    }
], function (err) { 
    if (err) return null;
}); 

此代码用于测试目的,我读取了前 1024 block 以查看 API 响应是否正确。

谢谢!

最佳答案

我相信您的问题可能出在这里:

JSON.parse(media).media_id

尝试:

JSON.parse(media).media_id_string

关于node.js - Twitter API POST 媒体/上传(分块)错误 "Not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31963364/

相关文章:

node.js - 无主机可用错误 : All host(s) tried for query failed

javascript - polymer 1.0 : Help using dom-if

java - 说一个方法读取一个字节的数据是什么意思?

json - 如何从 dispatch.json.JsObject 中提取

推特:推特发布后推特卡片不显示图像

Node.js 命名空间

node.js - Node 全局模块和 require() 中的包含有区别吗?

Twitter 搜索 (atom) API - 排除转发

node.js - 计算机逻辑核心和nodejs线程池之间的关系

javascript - jQuery:请求 getJSON + SunlightLabs API 帮助