HauLe
HauLe

Reputation: 21

Error 400: invalid_scope for Google Keep API with OAuth 2.0

I am encountering an error while trying to use the Google Keep API in my application. When I attempt to authenticate and access the API with the scope https://www.googleapis.com/auth/keep, I receive the following error message: Error 400: invalid_scope Some requested scopes cannot be shown: [https://www.googleapis.com/auth/keep] Steps Taken API Enablement: I have verified that the Google Keep API is enabled in my Google Cloud project. OAuth Consent Screen: I have set up the OAuth consent screen and attempted to add the scope manually, but it is marked as invalid when added:

https://www.googleapis.com/auth/keep

Code Snippet: Here’s a snippet of the relevant code I am using for authentication:

import os 
import json
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow

SCOPES = ['https://www.googleapis.com/auth/keep']

def authenticate():
    creds = None
    if os.path.exists('token.json'):
        creds = Credentials.from_authorized_user_file('token.json', SCOPES)

    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'client_secret.json', SCOPES)
            creds = flow.run_local_server(port=8080)

        with open('token.json', 'w') as token:
            token.write(creds.to_json())

    return creds

creds = authenticate()

I expected to successfully authenticate my application using the Google Keep API with the scope https://www.googleapis.com/auth/keep and create or retrieve notes without encountering any errors related to invalid scopes.

Upvotes: 1

Views: 61

Answers (0)

Related Questions