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

2023-09-14 23:07:56 作者:毒瘾︶°

我试着去更新用我的AngularJS应用YouTube API将V3视频的元数据。我能够使用插入上传的视频。

我不得不尝试设置在同一时间上传的视频元数据无限的问题,那种决定它只是不会发生,除非谁能告诉我不同​​。另一种方法是使用API​​的视频更新动作的元数据集 https://开头developers.google.com/youtube/v3/docs/videos/update 。

我recieving 400(坏请求)

  { 错误:{  错误:   {    域:全局,    原因:badContent    消息:不支持的内容类型:应用程序/ JSON的;字符集= UTF-8   }  ]  code:400,  消息:不支持的内容类型:应用程序/ JSON的;字符集= UTF-8 }} 

我的继承人$ http请求

  $ HTTP({  方法:PUT  网址:https://www.googleapis.com/upload/youtube/v3/videos?part=snippet,id  标题:{    授权:'承载'+ my_google_token  },  数据:{    ID:my_video_id    片段:{      标题:我的视频标题      介绍:我的视频描述,      标签:'我的','视频','标签'],      的categoryId:'17'     }   } })。然后(功能(响应){   的console.log(成功); },功能(错误){   的console.log(错误); }); 

解决方案

正确的答案是不使用$ HTTP,转而使用谷歌用于在JavaScript的YouTube上传提供的库。

虽然有点混乱,API参考/指令页面是在这里: https://developers.google.com/youtube/v3/$c $ c_samples / JavaScript的#upload_video

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

asp.net mvc angularjs web api单页应用之CRUD操作

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

解决方案

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

 
精彩推荐
图片推荐