Python - YouTube API v3 - How to get video ID only?

后端 未结 2 729
盖世英雄少女心
盖世英雄少女心 2021-01-25 16:58

How can I get only video ID of video? As I know, I should use fields for that but I don\'t understand how do they work. My code:

service = build(\'youtube\', \'v         


        
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-25 17:18

    Try out below code:

    import requests
    import json
    payload = {'part': 'snippet', 'key': DEVELOPER_KEY, 'order':'viewCount', 'q': 'A R Rahman', 'maxResults': 1}
    l = requests.Session().get('https://www.googleapis.com/youtube/v3/search', params=payload)    
    resp_dict = json.loads(l.content)
    print resp_dict['items']
    for i in resp_dict['items']:
       print "VideoId: ",i['id']['videoId']
    

提交回复
热议问题