【问题标题】:Python - YouTube API v3 - How do I get just the video ID of the top search result?Python - YouTube API v3 - 如何仅获取热门搜索结果的视频 ID?
【发布时间】:2020-12-29 09:43:20
【问题描述】:

我正在尝试仅获取顶部搜索结果的视频 ID 作为变量。

这就是我所拥有的:

from googleapiclient.discovery import build
api_key = 'API_KEY'
youtube = build('youtube', 'v3', developerKey=api_key)

request = youtube.search().list(
    part='id',
    maxResults=1,
    q='surfing',
    type='video',
    fields='items/id'
    )

response = request.execute()

print(response)

【问题讨论】:

    标签: python youtube-data-api


    【解决方案1】:
    {
        'id': {
            'kind': 'youtube#video', 
            'videoId': '_qbPlSXat4w'
        }
    }
    

    您只是想获得“videoId”,对吗? 试试看:

    print(response['items'][0]['id']['videoId'])
    

    【讨论】:

      猜你喜欢
      • 2014-07-28
      • 2013-01-09
      • 2016-10-26
      • 2017-09-17
      • 1970-01-01
      • 2017-09-17
      • 2018-04-18
      • 2021-02-18
      • 2019-12-14
      相关资源
      最近更新 更多