Get comment or likes count for YouTube video using

2020-03-30 02:11发布

I want to get number of comments and/or likes for video with specific YouTube ID. I am using YouTube API v3.0.

I was searching through API documentation and can't find appropriate method.

2条回答
唯我独甜
2楼-- · 2020-03-30 02:59

If you want number of comments and/or likes for video with specific YouTube ID, you need to use the YouTube API V3 with youtube.videos.list

with the parameters :

part=id, statistics
id=VIDEO_ID

This is the output :

 "items": [
  {

   "kind": "youtube#video",
   "etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/-hharrXKffaZ3z4sIleW9K-Nf2Q\"",
   "id": "_RtGuUAQOC4",
   "statistics": {
    "viewCount": "484851",
    "likeCount": "3993",
    "dislikeCount": "72",
    "favoriteCount": "0",
    "commentCount": "262"
   }
  }
 ]

LIVE DEMO

You can find all informations about video list in the doc :https://developers.google.com/youtube/v3/docs/videos/list?hl=fr :

查看更多
一夜七次
3楼-- · 2020-03-30 02:59

After having better look at Google API documentation here, I have found that I can use "statistics" part parameter of Videos.List API in order to get what I want.

Exact HTTP post request should be (notice part=statistics parameter):

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

And response is:

{
 "kind": "youtube#videoListResponse",
 "etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/XN5YXMZGQaruwTWTekZu7fQthdY\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {

   "kind": "youtube#video",
   "etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/QbzZs_aBNpzkZJxTVM7YgQeEY3g\"",
   "id": "sTPtBvcYkO8",
   "statistics": {
    "viewCount": "3215321",
    "likeCount": "17003",
    "dislikeCount": "263",
    "favoriteCount": "0",
    "commentCount": "621"
   }
  }
 ]
}
查看更多
登录 后发表回答