Resolving 'Client secrets must be for web or installed app' error when linking Notion API to Google Sheets

I’m new to coding and I’m trying to connect Notion to Google Sheets. But I keep getting an error saying ‘Client secrets must be for a web or installed app’. I’ve looked at different guides online but can’t figure it out. Here’s a simplified version of what I’m trying to do:

import google_auth_stuff
import notion_stuff

def get_google_sheet_data():
    # Set up Google Sheets connection
    auth = google_auth_stuff.get_credentials('my_secret_file.json')
    sheet = google_auth_stuff.connect_to_sheet(auth, 'SHEET_ID', 'RANGE')
    return sheet.get_values()

def update_notion_database(data):
    # Connect to Notion
    notion = notion_stuff.NotionClient('MY_NOTION_TOKEN')
    
    # Clear old data
    notion.clear_database('DATABASE_ID')
    
    # Add new data
    for row in data:
        notion.add_row('DATABASE_ID', row)

sheet_data = get_google_sheet_data()
update_notion_database(sheet_data)

Can anyone help me figure out what I’m doing wrong? Thanks!

hey man, i had a similar issue. i switched from service acct creds to oauth2 ones. in the google cloud console, create a project, enable sheets api, and generate oauth2 client id for a desktop app. rename file to client_secrets.json and update code accordingly. hope it helps!

I encountered this error before and discovered it was due to using the wrong type of credentials. The root problem was that the Sheets API requires OAuth 2.0 Client ID credentials configured for a web or installed app instead of service account credentials. I resolved this by creating a new project in the Google Cloud Console, enabling the Sheets API, and generating an OAuth 2.0 Client ID with the Desktop app option. After downloading the configuration file and renaming it to client_secrets.json, I updated my code as follows:

from google_auth_oauthlib.flow import Flow

flow = Flow.from_client_secrets_file('client_secrets.json', scopes=['https://www.googleapis.com/auth/spreadsheets.readonly'])
creds = flow.run_local_server(port=0)

This approach resolved the error. Be sure to manage token refresh and storage for subsequent runs.

The error you are encountering typically indicates that you are not using the proper type of Google Cloud credentials. In my experience, using OAuth 2.0 credentials configured for a Desktop app rather than service account keys resolves the issue. You should create a new project in the Google Cloud Console, enable the Sheets API, and generate OAuth 2.0 credentials with the Desktop app option. After downloading and renaming your configuration file to client_secrets.json, update your code to include an authorization flow. Also, ensure your Notion integration has the necessary permissions.