我有一个实现youtube插入api的ionic 3应用程序,以便将视频上传到youtube服务器。我从OAuth游乐场获得了承载令牌,但是即使我的令牌尚未过期,也总是返回错误。
uploadVideo() {
const fileTransfer: FileTransferObject = this.transfer.create();
let header = {
"Authorization": "Bearer XXX",
"Accept": "video/*",
"Content-Type": "video/*"
};
let param = {
"snippet": {
"categoryId": "22",
"description": "Description of uploaded video.",
"title": "Test video upload."
},
"status": {
"privacyStatus": "private"
}
};
let options: FileUploadOptions = {
fileKey: 'big_buck_bunny_720p_1mb',
fileName: 'big_buck_bunny_720p_1mb',
chunkedMode: true,
mimeType: "video/*",
headers: header,
params: param
};
fileTransfer.upload("https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4", 'https://www.googleapis.com/upload/youtube/v3/videos?part=snippet%2Cstatus&key=' + this.apiKey, options)
.then((data) => {
console.log(data + " Uploaded Successfully");
}, (err) => {
console.log(JSON.stringify(err) + "this");
});
}
返回错误消息:
"{"code":1,"source":"https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4","target":"https://www.googleapis.com/upload/youtube/v3/videos?access_token=xxxx&part=snippet%2Cstatus&key=xxxx","http_status":401,"body":"{\n \"error\": {\n \"errors\": [\n {\n \"domain\": \"global\",\n \"reason\": \"authError\",\n \"message\": \"Invalid Credentials\",\n \"locationType\": \"header\",\n \"location\": \"Authorization\"\n }\n ],\n \"code\": 401,\n \"message\": \"Invalid Credentials\"\n }\n}","exception":"https://www.googleapis.com/upload/youtube/v3/videos?access_token=ya29.GltCB8sgGIvujhHIfU50Me-MmHrDCCmaRdtf6wPiEPtaKa69RD60nJMYx-XtyRy-V1SD6QJgLtOmhqwg8FV2g8ScZ6YZUg2JM5vFJf31BE6ptR764AXjRuQS72Zg&part=snippet%2Cstatus&key=AIzaSyC42HvyrTKJ3AmuxYF-GVGmtfWTH9GJ8dg"}this", source: file:///android_asset/www/build/main.js (5604)