400 Bad Request on Youtube API Update using AngularJS

匆匆过客 提交于 2019-12-23 01:24:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!