【问题标题】:Youtube api detect live videoYoutube api 检测实时视频
【发布时间】:2020-06-08 14:15:51
【问题描述】:

有没有办法使用视频列表检测实时视频?如果您有视频 ID,或者其他方式?

https://www.googleapis.com/youtube/v3/videos?id=8WbMEmtUckA&key=API_KEY&part=id,snippet

我在这里没有看到这个信息:https://developers.google.com/youtube/v3/docs/videos/list

【问题讨论】:

  • 一个选项在this answer 或同一链接中接受的答案中描述。

标签: youtube-api live


【解决方案1】:

另一种方式;您可以尝试使用 Youtube 搜索列表,只需将 eventType 参数设置为 live,您就会在结果中获得直播视频...

用于直播和当前观看次数最多的视频的 Python 示例

import os

import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors

scopes = ["https://www.googleapis.com/auth/youtube.force-ssl"]

def main():
    # Disable OAuthlib's HTTPS verification when running locally.
    # *DO NOT* leave this option enabled in production.
    os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"

    api_service_name = "youtube"
    api_version = "v3"
    client_secrets_file = "YOUR_CLIENT_SECRET_FILE.json"

    # Get credentials and create an API client
    flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
        client_secrets_file, scopes)
    credentials = flow.run_console()
    youtube = googleapiclient.discovery.build(
        api_service_name, api_version, credentials=credentials)

    request = youtube.search().list(
        part="snippet",
        eventType="live",
        maxResults=50,
        order="viewCount",
        type="video"
    )
    response = request.execute()

    print(response)

if __name__ == "__main__":
    main()

更多细节: YouTube 返回一个包含大量信息的长 json 文件。我们只想要“videoId”

example 'CZByYnUbAgI' 复制此 ID 并粘贴到 https://www.youtube.com/watch?v= 的末尾

【讨论】:

    猜你喜欢
    • 2019-08-27
    • 1970-01-01
    • 2016-10-26
    • 2013-08-24
    • 2013-01-14
    • 1970-01-01
    • 2017-02-16
    • 2014-07-04
    • 2021-05-03
    相关资源
    最近更新 更多