使用 youtube api v3 将视频插入播放列表 [英] insert video into a playlist with youtube api v3

查看:32
本文介绍了使用 youtube api v3 将视频插入播放列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我对 youtube api 相当熟悉 .. 我知道如何阅读频道和播放列表以及获取我认为重要的任何相关视频信息我正在使用 php 来完成所有这些工作,但为了确保我对每个请求/响应的工作方式有正确的认识,我在浏览器中使用 API 资源管理器进行了尝试

Hey so I am fairly familiar to the youtube api .. I know how to read channels and playlist along with getting any relevant video information I identify as Important I'm using php to do all of this but in order to make sure I have the correct idea of how each request/response works I attempted it in the browser with the API explorer

现在我正在尝试将视频插入我刚刚创建的播放列表(也通过 API),但我在弄清楚我的请求是如何不正确形成时遇到了一些麻烦

Now I am trying to insert videos into a playlist I just created (also through the API) but I am having some trouble figuring out exactly how my request is not properly formed

这是请求

POST https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&key={YOUR_API_KEY}

Content-Type:  application/json
Authorization:  Bearer ya29.1.AADtN_WT2TRZzH1t86nVlX26z9WPp-gnDTxVHGvdQ6xx0vyTzmkYeXkLdJerwllLzF_a
X-JavaScript-User-Agent:  Google APIs Explorer

{
  "snippet": {
    "playlistId": "PL8hD12HFC-nuswc21_e64aPAy9B25sEH7",
    "resourceId": {
      "videoId": "KMGuyGY5gvY"
    }
  }
} 

这里是回复

400 Bad Request

- Show headers -

{
 "error": {
  "errors": [
   {
     "domain": "youtube.playlistItem",
     "reason": "invalidResourceType",
     "message": "Resource type not supported."
   }
  ],
   "code": 400,
   "message": "Resource type not supported."
 }
}

播放列表是我使用 API Explorer 创建的可公开查看的空播放列表,可通过标准 youtube 网站查看.该视频是从 youtube 上随机选择的......尝试了一些,因为我认为这可能是视频的一个特定问题,但没有运气......我已经打开了 OAuth 并且正在使用一个经过验证的 YouTube 合作伙伴帐户

the playlist is an empty publicly viewable playlist I created using the API Explorer and is viewable through standard youtube website. The video is randomly selected off of youtube ... tried a few as thought it might be a specific problem with a video but no luck .. I have switched on OAuth and am using an account that is a verified youtube partner

但是我似乎可以弄清楚为什么不支持资源类型我环顾了网络以及左侧的答案而没有找到我做错了什么..对这个问题的任何帮助将不胜感激因为我现在有点卡住

However I can seemed to figure out why the resource type is not supported I've looked around the web along with answers to the left without finding exactly what I am doing wrong.. any help with this problem would be greatly appreciated as I am kind of stuck at the moment

推荐答案

您的 resourceId 不完整,因为它没有向 API 标识如何解释 videoId参数.尝试设置 resourceIdkind 属性,如下所示:

Your resourceId isn't complete, as it doesn't identify to the API how to interpret the videoId parameter. Try setting the kind attribute of the resourceId, like this:

  "snippet": {
    "playlistId": "PL8hD12HFC-nuswc21_e64aPAy9B25sEH7",
    "resourceId": {
      "kind": "youtube#video",
      "videoId": "KMGuyGY5gvY"
    }
  }

这样,API 就会知道在哪个域"(可以这么说)中定位由您发送的字符串标识的资源.

That way, the API will know in which 'domain' (so to speak) to locate the resource identified by the string you send in.

这篇关于使用 youtube api v3 将视频插入播放列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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