使用AngularJS在Youtube API更新400错误的请求 [英] 400 Bad Request on Youtube API Update using AngularJS

查看:457
本文介绍了使用AngularJS在Youtube API更新400错误的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着去更新用我的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

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

这篇关于使用AngularJS在Youtube API更新400错误的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆