使用Youtube API获取视频列表和使用gdata的开发者键的观看次数



我在python中工作,我想使用YouTube API来抓取视频声明列表和使用我的YouTube开发人员密钥和gdata的观看次数。这可能吗?

我想我未编辑的代码将适用于您的应用程序。

代码:

import requests
import json 
import pandas  
key = "xxx"
url = "https://www.googleapis.com/youtube/v3/search?part=snippet&order=viewCount&publishedAfter=2015-06-08T00%3A00%3A00Z&key="+key+
"&type=video&maxResults=50&relevanceLanguage=en&videoDuration=short&videoCategoryId=15,18,23,44"
content = json.loads(requests.get(url).text)
def get_youtoube_content(content):
    id = []
    kind=[]
    description = []
    title = []
    time =[]
    for i in content["items"]:
        a=i["id"]
        b=i["snippet"]
        id.append(a["videoId"])
        kind.append(a["kind"])
        description.append(b["description"])
        title.append(b["title"])
        time.append(b["publishedAt"])
    data = pandas.DataFrame({"id":id, "type":kind,"description":description ,"title":title,"time":time })
    return(data)
data=get_youtoube_content(content)
stat_url="https://www.googleapis.com/youtube/v3/videos?part=statistics&key="+key+"&maxResults=50&id="+str(list(data["id"])).replace("[","").replace("]","").replace("'","")
stat_content = json.loads(requests.get(stat_url).text)
def get_youtoube_content_stat(content):
    id = []
    commentCount=[]
    dislikeCount = []
    favoriteCount = []
    likeCount=[]
    viewCount=[]
    for i in content["items"]:
        id.append(i["id"])
        b=i["statistics"]
        commentCount.append(b["commentCount"])
        dislikeCount.append(b["dislikeCount"])
        favoriteCount.append(b["favoriteCount"])
        likeCount.append(b["likeCount"])
        viewCount.append(b["viewCount"])
    data = pandas.DataFrame({"id":id, "commentCount":commentCount,"dislikeCount":dislikeCount ,"favoriteCount":favoriteCount,"likeCount":likeCount, "viewCount":viewCount })
    return(data)
data_stat=get_youtoube_content_stat(stat_content)
data=pandas.merge(data, data_stat,"inner", on="id" )

相关内容

  • 没有找到相关文章

最新更新