有没有一种方法可以使用视频列表检测实时视频?或者其他方式,如果你有视频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
另一种方式;您可以尝试使用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">
示例"CZByYnUbAgI"复制此Id并粘贴到的末尾https://www.youtube.com/watch?v=