Youtube视频持续时间API v3 [英] Youtube Video Duration API v3

查看:88
本文介绍了Youtube视频持续时间API v3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我对youtube的api v3有一点问题。

Hey guys i have a little problem with the api v3 of youtube.

问题是,如果json有这种结构

Question is, if the json have this structure

{
 "kind": "youtube#videoListResponse",
 "etag": "\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/1jshwBhrF6O49W3oUmNF7rmkgAQ\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#video",
   "etag": "\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/Zji9LPuiDCpb4GjgPpzdGgf85ws\"",
   "id": "3wFq1-pK05o",
   "contentDetails": {
    "duration": "PT1M1S",
    "dimension": "2d",
    "definition": "hd",
    "caption": "true",
    "licensedContent": true
   }
  }
 ]
}

我想要像这样获得视频时长

$.getJSON( "https://www.googleapis.com/youtube/v3/videos?id=XXXX&key=XXXXX&part=contentDetails", function( json ) {
  document.write( "JSON Data: " + json["items"]["contentDetails"]["duration"] );
 }); 

但它不起作用!
我不明白什么是错的。在我发疯之前请帮助我。

But it doesn't work! I do not understand what's wrong. Please help me before I go crazy.

推荐答案

试试这个:

var json = {
    "kind": "youtube#videoListResponse",
    "etag": "\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/1jshwBhrF6O49W3oUmNF7rmkgAQ\"",
    "pageInfo": {
        "totalResults": 1,
        "resultsPerPage": 1
    },
    "items": [{
        "kind": "youtube#video",
        "etag": "\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/Zji9LPuiDCpb4GjgPpzdGgf85ws\"",
        "id": "3wFq1-pK05o",
        "contentDetails": {
            "duration": "PT1M1S",
            "dimension": "2d",
            "definition": "hd",
            "caption": "true",
            "licensedContent": true
        }
    }]
}
console.log(json.items[0].contentDetails.duration);

这篇关于Youtube视频持续时间API v3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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