【问题标题】:400 Bad Request on Youtube API Update using AngularJS使用 AngularJS 对 Youtube API 更新的 400 错误请求
【发布时间】:2015-12-28 10:36:25
【问题描述】:

我正在尝试在我的 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);
 });

【问题讨论】:

  • 你有没有想过如何在原始 POST 上传时设置 sn-p?我遇到了类似的问题..我的上传工作正常,但它从未真正设置 sn-p 的标题和描述。

标签: javascript angularjs youtube youtube-data-api


【解决方案1】:

您还需要在 URI 中提供“uploadType=resumable”参数

【讨论】:

    【解决方案2】:

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

    虽然有些混乱,API 参考/说明页面在这里: https://developers.google.com/youtube/v3/code_samples/javascript#upload_video

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

    【讨论】:

      猜你喜欢
      • 2011-06-18
      • 2018-09-10
      • 1970-01-01
      • 1970-01-01
      • 2019-11-10
      • 2015-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多