Access blocked: This app’s request is invalid

Please assist with this code. I am trying to build a data pipeline using Python to connect to Google Bigquery. I am having trouble getting a token etc.

My code is

import os

import requests

from import storage

Replace the following with your own values

client_id = ‘

client_secret = ‘GOCSPX-3r’

redirect_uri = ‘

scope = ‘YOUR_SCOPES’ # e.g. ‘

Update with provided information

client_id = ‘

client_secret = ‘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’

redirect_uri = ’

scope = ‘

Step 1: Redirect the user to the authorization URL

authorization_url = f’Sign in - Google Accounts

print(‘Please go to the following URL to authorize the application:’)


Step 2: Retrieve the authorization code from the user

authorization_code = input('Enter the authorization code: ')

Step 3: Exchange the authorization code for an access token and refresh token

token_url = ‘

token_payload = {

‘code’: authorization_code,

‘client_id’: client_id,

‘client_secret’: client_secret,

‘redirect_uri’: redirect_uri,

‘grant_type’: ‘authorization_code’


token_response =, data=token_payload)

token_data = token_response.json()

Access token and refresh token

access_token = token_data[‘access_token’]

refresh_token = token_data[‘refresh_token’]

Use the access token to make API requests

e.g. headers = {‘Authorization’: f’Bearer {access_token}'}

response = requests.get(‘’, headers=headers)


Firstly, there’s something wrong with the block quoting, so only the first part is readable.

Secondly, your secrets are now exposed. You’ll need to regenerate them.

Third, though: You seem to have duplicate assignments here; it’s possible the first one is correct, but I suspect the second one isn’t (unless it’s caused by a post format issue). Make sure the redirect_uri matches what you told Google that you’d be using.