您可以在此处尝试查询:
https://developers.google.com/youtube/v3/docs/search/list#try-it
我相信以下查询是您只想搜索和检索视频 ID 的方式:
https://www.googleapis.com/youtube/v3/search?part=id&q= {NAME}&type=video&fields=items%2Fid&key={YOUR_API_KEY}
例如,如果 {NAME} 是 psy,则此调用返回以下数据,您可以从中检索其中一项的 videoId;
{
"items": [
{
"id": {
"kind": "youtube#video",
"videoId": "9bZkp7q19f0"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "Ecw4O5KgvsU"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "o443b2rfFnY"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "WOyo7JD7hjo"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "QZmkU5Pg1sw"
}
}
]
}
如果您修改 python 客户端库中包含的示例:
https://developers.google.com/api-client-library/python/
你可以这样做:
search_response = service.search().list(
q="google",
part="id",
type="video",
fields="items/id"
).execute()
videos = []
for search_result in search_response.get("items", []):
videos.append("%s" % (search_result["id"]["videoId"]))
print "Videos:\n", "\n".join(videos), "\n"