问题描述
到目前为止,我一直在使用此 URL 来检索频道的订阅者数量:
Until now I've been using this URL to retrieve subscriber count for a channel:
http://gdata.youtube.com/feeds/api/users/<channel_id>?v=2&alt=json
还有这个获取频道视频数的网址:
And this URL to get channel videos count:
https://gdata.youtube.com/feeds/api/users/<channel_id>/uploads?v=2&alt=jsonc&max-results=0
但从今天起,Google 停止使用它的 v2 API,我找不到这些数据的替代选项.
But from this day Google discontinued using it's v2 API and I can't find replacement options for this data.
推荐答案
您将要使用 Channels/list 端点,作为 part
参数的 statistics
传入.
You're going to want to use the Channels/list endpoint as pass in statistics
for the part
parameter.
请求:
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
参数传入以逗号分隔的频道 ID 列表.因为我只传入了一个 id
,items
数组的第一个对象将包含您需要的值.在 statistics
字典中为您想要的数据获取 subscriberCount
和 videoCount
值的对象.
You can pass in a comma-separated list of Channel IDs for the id
parameter. Because I only passed in one id
, the first object of the items
array will have the values you need. Get the object for the subscriberCount
and videoCount
values in the statistics
dictionary for the data you want.
这篇关于如何获取给定 YouTube 频道的订阅者数量和视频数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!