如何解决按国家/地区搜索 YouTube 视频
我正在研究某些国家/地区人们对冠状病毒疫苗的看法。所以我想提取关注这个主题的YouTube视频,但我不知道如何有效地使用属性“RegionCode”。我试过这个脚本,但它不起作用。有没有人可以帮我输入正确的代码?
youtube=service
def youtube_search(q,max_results=50,order="relevance",token=None,location=None,location_radius=None):
#youtube = build(YOUTUBE_API_SERVICE_NAME,YOUTUBE_API_VERSION,developerKey=DEVELOPER_KEY)
search_response = youtube.search().list(
q=q,type="video",pagetoken=token,order = order,part="id,snippet",# Part signifies the different types of data you want
maxResults=max_results,location=location,locationRadius=location_radius).execute()
title = []
channelId = []
channelTitle = []
categoryId= []
regionCode= []
videoId = []
viewCount = []
likeCount = []
dislikeCount = []
commentCount = []
favoriteCount = []
category = []
tags = []
videos = []
for search_result in search_response.get("items",[]):
if search_result["id"]["kind"] == "youtube#video":
title.append(search_result['snippet']['title'])
videoId.append(search_result['id']['videoId'])
response = youtube.videos().list(
part='statistics,snippet',id=search_result['id']['videoId']).execute()
channelId.append(response['items'][0]['snippet']['channelId'])
channelTitle.append(response['items'][0]['snippet']['channelTitle'])
categoryId.append(response['items'][0]['snippet']['categoryId'])
regionCode.append(response['items'][0]['snippet']['regionCode'])
favoriteCount.append(response['items'][0]['statistics']['favoriteCount'])
viewCount.append(response['items'][0]['statistics']['viewCount'])
#likeCount.append(response['items'][0]['statistics']['likeCount'])
#dislikeCount.append(response['items'][0]['statistics']['dislikeCount'])
if 'commentCount' in response['items'][0]['statistics'].keys():
commentCount.append(response['items'][0]['statistics']['commentCount'])
else:
commentCount.append([])
if 'tags' in response['items'][0]['snippet'].keys():
tags.append(response['items'][0]['snippet']['tags'])
else:
tags.append([])
#youtube_dict = {'tags':tags,'channelId': channelId,'channelTitle': channelTitle,'categoryId':categoryId,'title':title,'videoId':videoId,'viewCount':viewCount,'likeCount':likeCount,'dislikeCount':dislikeCount,'commentCount':commentCount,'favoriteCount':favoriteCount}
youtube_dict = {'tags':tags,'favoriteCount':favoriteCount}
return youtube_dict
q = "coronavirus vaccine"
test = youtube_search(q,max_results=100,location_radius=None)
test.keys()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。