How to get subscriber count and videos count for a given YouTube channel?

前端 未结 1 1659
我寻月下人不归
我寻月下人不归 2020-12-17 05:14

Until now I\'ve been using this URL to retrieve subscriber count for a channel:

http://gdata.youtube.com/feeds/api/users/?v=2&alt=json
         


        
相关标签:
1条回答
  • 2020-12-17 05:30

    You're going to want to use the Channels/list endpoint as pass in statistics for the part parameter.

    Request:

    HTTP GET: GET https://www.googleapis.com/youtube/v3/channels?part=statistics&id={CHANNEL_ID}&key={YOUR_API_KEY}
    

    Response (with 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"
       }
      }
     ]
    }
    

    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.

    0 讨论(0)
提交回复
热议问题