How to retrieve like/dislike/view count from Youtu

2019-06-05 03:30发布

问题:

I want to get some minimal statistic Information from a youtube-video for "like", "dislike", "view" count. However, i got so far, that i can retrieve the JSON for the Videoinformation, but there is none of the above mentioned information.

回答1:

So, without using the Google API and and doing any O-AUTH, i am just parsing the website and getting like count and title.

import requests import re

filesInChannel = [
"https://www.youtube.com/watch?v=PYuNBFdwK7k",
"https://www.youtube.com/watch?v=-Ox9MvottBI"
]

def getStats(link):
    page = requests.get(link)
    likes = re.search("with (\d*.\d*.\d*)", page.text).group(1)
    title = re.search("property=\"og:title\" content=\"([^\n]*)", page.text).group(1)
    return (likes, title)


for link in filesInChannel:
    stats = getStats(link)
    print stats[0].encode("utf-8") + " " + stats[1].encode("utf-8")


回答2:

Have you tried videos/getRating

Valid values for this property are:

  • dislike
  • like
  • none
  • unspecified

Example:

GET https://www.googleapis.com/youtube/v3/videos/getRating?id=test>&key=<key>


回答3:

The following query using the youtubeAnalytics.reports.query portion of the YouTube Analytics API v1 will return the count of views, likes, and dislike counts for the channel and time span specified:

GET https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel=={CHANNEL_ID}&start-date=2018-02-18&end-date=2018-03-26&metrics=views,likes,dislikes&key={YOUR_API_KEY}

Running the query does require the user to be authorized. You can use the APIs Explorer to test and modify the above query.