Youtube 上的 400 错误请求 API 使用更新 AngularJS

400 Bad Request on Youtube API Update using AngularJS

我正在尝试使用 AngularJS 应用中的 Youtube API V3 更新视频的元数据。我可以使用插入上传视频。

我在尝试在上传的同时设置视频元数据时遇到了无限的问题,并且确定它不会发生,除非有人能告诉我不同​​的方法。另一种方法是使用 api https://developers.google.com/youtube/v3/docs/videos/update.

的视频更新操作来设置元数据

我收到 400(错误请求)

{
 "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"
 }
}

这是我的 $http 请求

$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);
 });

正确答案是不使用 $http,而是使用 google 提供的库在 javascript 中上传到 YouTube。

虽然有些混乱,但 API reference/instructions 页面位于此处: https://developers.google.com/youtube/v3/code_samples/javascript#upload_video

这些代码文件可以在 github 上找到: https://github.com/youtube/api-samples/tree/master/javascript

您还需要在 URI

中提供 "uploadType=resumable" 参数