为什么当我附加分块数据时它会返回
"{"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/