如何以JSON格式获取特定YouTube频道的即将播出的直播活动

时间:2015-04-20 13:15:46

标签: javascript jquery json youtube youtube-livestreaming-api

我正在使用jQuery Mobile框架开发混合/移动应用程序,我想从特定用户/频道检索实时事件提要(即将推出或推荐)。我用这种方式尝试了一些事情:https://gdata.youtube.com/feeds/api/users/albpower2/events

我得到了一个

  

此操作所需的开发人员密钥

消息。

我创建了一个I开发人员密钥,但我不知道如何包含在此URL API调用中。

更新: 我找到了Youtube v3 Data API以及它们在线API测试平台的功能,但是当我尝试直接从浏览器执行这些功能时,它说需要OAuth身份验证。我不知道如何设置该OAuth密钥并从URL中获取该功能

来自此GET请求https://www.googleapis.com/youtube/v3/liveBroadcasts?part=snippet&broadcastStatus=all&key=AIzaSyDhDZjburmzpaoH39Uj4dnU6X_GRLbCVW0  这是回复:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

我从这个链接获得这些信息:https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.liveBroadcasts.list?part=snippet&broadcastStatus=all&_h=19&

2 个答案:

答案 0 :(得分:2)

只需将其包含在API调用的网址中:

https://gdata.youtube.com/feeds/api/users/albpower2/events?key=YOUR_API_KEY

来自the docs

答案 1 :(得分:0)

I was looking for a more natural way to work this out but I ended with an improvisation, instead of retrieving Live events feed from a channel I am creating manually an playlist and after creating an event I add it there and from there I display to the app. So for now its working solution till there is an javascript solution for API v3 to solve this with creating automatically Access tokens.

So for retrieving items from playlist using API v3 the method is something like this: https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId={your_playlist_ID}&key={your_API_KEY}