How to retrieve like/dislike/view count from Youtube?

天大地大妈咪最大 提交于 2020-01-03 01:27:12

问题


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.



来源:https://stackoverflow.com/questions/32940484/how-to-retrieve-like-dislike-view-count-from-youtube

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!