0

I trying to write code to access the Youtube API in python. I followed the sample code get authenticated for Google API. When I run this I get a message

Access blocked: MyAPP request is invalid

I have no idea why I get this. Any advise would be appreciated.

from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow

# Replace with the path to your downloaded client_secret.json file
CLIENT_SECRETS_FILE = 'client_secret.json'

# Define the scopes your application needs
SCOPES = ['https://www.googleapis.com/auth/youtube.readonly']

API_SERVICE_NAME = 'youtube'
API_VERSION = 'v3'

def get_authenticated_service():
    flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS_FILE, SCOPES)
    credentials = flow.run_local_server(open_browser=False)  # Or flow.run_local_server() for web apps
    return build(API_SERVICE_NAME, API_VERSION, credentials = credentials)

# Now you can use the authenticated service to make YouTube API calls
youtube = get_authenticated_service()
3
  • 1
    Are you sure your client secrets are valid? Commented Jun 10 at 2:09
  • Its the file I downloaded from the credentials page. Commented Jun 10 at 15:28
  • The problem seems to be that its a limited input device using the loopback uri. explained here developers.google.com/identity/protocols/oauth2/resources/…, but I don't understand how to fix this in python Commented Jun 25 at 13:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.