YouTube live chat in Python: pageTokenInvalid error

Viewed 638

next: YouTube live chat in Python Flask: pageTokenInvalid error
I want to retrieve my YouTube live stream chat's using the YouTube Data API in Python.

On the official doc web page of the YouTube Live Streaming API I used Try this 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()

But the I got response was:

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

What is the pageTokenInvalid error and how can I get the pageToken?

0 Answers
Related