Python 中的 YouTube 实时聊天:pageTokenInvalid 错误

问题描述

一个YouTube live chat in Python Flask: pageTokenInvalid error
我想使用 Python 中的 YouTube 数据 API 检索我的 YouTube 直播聊天。

在我使用的 YouTube Live Streaming API 的官方文档网页上试试这个 API

# Sample Python code for youtube.liveChatMessages.list
# See instructions for running these code samples locally:
# https://developers.google.com/explorer-help/guides/code_samples#python

import os

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

scopes = ["https://www.googleapis.com/auth/youtube.readonly"]

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.liveChatMessages().list(
        liveChatId="YOUR_CHAT_ID",part="snippet,authorDetails"
    )
    response = request.execute()

    print(response)

if __name__ == "__main__":
    main()

但我得到的回应是:

{
  "error": {
    "code": 400,"message": "page token is not valid.","errors": [
      {
        "message": "page token is not valid.","domain": "youtube.liveChat","reason": "pagetokenInvalid"
      }
    ]
  }
}

什么是 pagetokenInvalid 错误以及如何获得 pagetoken

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)