【发布时间】:2021-05-19 07:43:30
【问题描述】:
使用 PHP 我可以从 API 中获取一些信息,但我无法获取完整的 API。
这是我目前拥有的:
// url with $vID being my video ID and $API_key being the access key
$api_url = 'https://www.googleapis.com/youtube/v3/videos?part=status&id=' . $vID . '&key=' . $API_key;
// get contents
$videoInfo = file_get_contents( $api_url );
这将为我提供 API 的第一个块,如下所示:
VidInfo: { "kind": "youtube#videoListResponse",
"etag": "xxxxxxxxxxxxxx",
"items": [
{ "kind": "youtube#video",
"etag": "yyyyyyyyyyy",
"id": "zzzzzz",
"status": {
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true,
"madeForKids": false
}
}
],
"pageInfo": { "totalResults": 1, "resultsPerPage": 1 }
}
但是,完整的 API 响应应如下所示:
{
"kind": "youtube#videoListResponse",
"etag": "\"mPrpS7Nrk6Ggi_P7VJ8-KsEOiIw/el3Y0P65UwM366CJD3POX-W4y0c\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"mPrpS7Nrk6Ggi_P7VJ8-KsEOiIw/Rn64PVwC0Uhr4xp41vDOqygjJ9c\"",
"id": "VIDEO_ID",
"contentDetails": {
"duration": "PT10M6S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": false,
"contentRating": {
"ytRating": "ytAgeRestricted"
}
}
}
]
}
我特别感兴趣的是 ytRating 以查看视频是否受到限制,但我无法在收到的回复中找到它。
谁能帮帮我?
【问题讨论】:
-
您只要求
status部分,显然您也想要求contentDetails。 developers.google.com/youtube/v3/docs/videos/list#parameters -
为什么不使用 PHP 客户端库?
标签: php youtube-api youtube-data-api