问题
Im trying to update a video's metadata using the Youtube API V3 in my AngularJS app. I am able to upload the video using insert.
I had unlimited problems trying to set the video metadata at the same time as uploading and kind of determined it just wasn't going to happen, unless anyone can tell me differently. The alternative is to set the metadata using the videos update action of the api https://developers.google.com/youtube/v3/docs/videos/update.
I'm recieving a 400 (Bad Request)
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badContent",
"message": "Unsupported content with type: application/json;charset=UTF-8"
}
],
"code": 400,
"message": "Unsupported content with type: application/json;charset=UTF-8"
}
}
Heres my $http request
$http({
method: "PUT",
url: "https://www.googleapis.com/upload/youtube/v3/videos?part=snippet,id",
headers: {
Authorization: 'Bearer ' + my_google_token
},
data: {
id: "my_video_id",
snippet: {
title: "my video title",
description: "my video description",
tags: ['my','videos','tags'],
categoryId: '17'
}
}
}).then(function(response){
console.log('success');
},function(error){
console.log(error);
});
回答1:
The correct answer is to not use $http and instead use the google provided library for youtube uploading in javascript.
Although somewhat confusing, the API reference/instructions page is here: https://developers.google.com/youtube/v3/code_samples/javascript#upload_video
Those code files can be found here on github: https://github.com/youtube/api-samples/tree/master/javascript
回答2:
You also need to provide the "uploadType=resumable" parameter in the URI
来源:https://stackoverflow.com/questions/32869525/400-bad-request-on-youtube-api-update-using-angularjs