【问题标题】:Returning duration while listing playlistItems?列出播放列表项时返回持续时间?
【发布时间】:2014-06-24 22:58:41
【问题描述】:

我正在使用这个网址:

https://www.googleapis.com/youtube/v3/playlistItems?
    playlistId=FLFe0SGNFqZ9E2owO5ZDZpeg&
    part=snippet,contentDetails,status

获取 YouTube 播放列表项。

我包含了我感兴趣的所有part,但是我发现无法返回该项目的duration

https://developers.google.com/youtube/v3/docs/playlistItems/list

这可能吗?

目前我只取回这样的物品:

{
  "status": {
    "privacyStatus": "public"
  }, 
  "kind": "youtube#playlistItem", 
  "contentDetails": {
    "videoId": "tL-Ba86UhoE"
  }, 
  "snippet": {
    "playlistId": "FLFe0SGeFqZ9E2owO5ZDZpwg", 
    "thumbnails": {
      "default": {
        "url": "https://i1.ytimg.com/vi/tL-BA86Uhoh/default.jpg", 
        "width": 120, 
        "height": 90
      }, 
      "high": {
        "url": "https://i1.ytimg.com/vi/tL-BA86Uhoh/hqdefault.jpg", 
        "width": 480, 
        "height": 360
      }, 
      "medium": {
        "url": "https://i1.ytimg.com/vi/tL-BA86Uhoh/mqdefault.jpg", 
        "width": 320, 
        "height": 180
      }
    }, 
    "title": "Music Video", 
    "resourceId": {
      "kind": "youtube#video", 
      "videoId": "tL-BA86Uhoh"
    }, 
    "channelId": "UCFe0SGNFqZ9E2owO5ZDZpwg", 
    "publishedAt": "2013-07-06T18:41:43.000Z", 
    "channelTitle": "channeltitle", 
    "position": 0, 
    "description": "Video for"
  }, 
  "etag": "\"ePFRUfYBkeQ2ncpP9OLHvB0fDw4/CJiCG6tvFw4quQlzJq3gTrhvCNo\"", 
  "id": "FL-fX6VqgtTfCJWKNE4aVRODKSrRgEdGvw"
}, 

根本没有时间指示。 我宁愿避免让 YouTube 泛滥成灾,要求返回单个视频的时长。

【问题讨论】:

    标签: youtube youtube-api youtube-data-api


    【解决方案1】:

    使用这样的链接获取许多视频的持续时间:

    https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=idFirst,idSecond&key=YOUR_API_KEY
    

    【讨论】:

    • 该问题是针对 playlistItems api 提出的。如果我们必须从 youtube 播放列表创建一个列表,我们可以传递多个 id。
    【解决方案2】:

    使用此功能:[仅与 Youtube Api v3 一起使用]

    浏览器:

    你必须发出另一个 http 请求 使用:

    https://www.googleapis.com/youtube/v3/videos?id={video id}&part=contentDetails&key={api Key}

    然后

    内容详情

    你会发现持续时间

    PHP :

    function getDuration($apiKey,$video_id){        
        $link='https://www.googleapis.com/youtube/v3/videos?id='.$video_id.'&part=contentDetails&key='.$apiKey;
        $data = json_decode(file_get_contents($link),true);
        $duration =  $data['items'][0]['contentDetails']['duration'];   
        return $duration;
     }
    

    【讨论】:

      猜你喜欢
      • 2018-08-16
      • 2017-07-14
      • 2021-12-21
      • 1970-01-01
      • 2023-02-03
      • 2013-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多