到目前为止,我一直在使用此 URL 来检索 channel 的订阅者数量:
http://gdata.youtube.com/feeds/api/users/<channel_id>?v=2&alt=json
这个用于获取 channel 视频计数的 URL:
https://gdata.youtube.com/feeds/api/users/<channel_id>/uploads?v=2&alt=jsonc&max-results=0
但是从今天起 Google 停止使用它的 v2 API,我找不到这些数据的替代选项。
最佳答案
您将要使用 Channels/list端点作为传入 statistics
为 part
范围。
要求:
HTTP GET: GET https://www.googleapis.com/youtube/v3/channels?part=statistics&id={CHANNEL_ID}&key={YOUR_API_KEY}
响应(与
id=UCt7iVnJwjBsof8IPLJHCTgQ
):{
"kind": "youtube#channelListResponse",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/WNxXCvycTyqTjTn9sLJ5toVjBRY\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/jijTuA_iWn2Kv9aRnqeAWNAcQ6I\"",
"id": "UCt7iVnJwjBsof8IPLJHCTgQ",
"statistics": {
"viewCount": "796662",
"commentCount": "20",
"subscriberCount": "257",
"hiddenSubscriberCount": false,
"videoCount": "126"
}
}
]
}
您可以为
id
传入以逗号分隔的 channel ID 列表。范围。因为我只通过了一个id
,items
的第一个对象数组将包含您需要的值。获取 subscriberCount
的对象和 videoCount
statistics
中的值你想要的数据的字典。
关于youtube - 如何获取给定 YouTube channel 的订阅者数量和视频数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30604742/