Access blocked: This app’s request is invalid

1,198 views
Skip to first unread message

Anthony Apollis

unread,
Apr 24, 2023, 10:36:07 AM4/24/23
to Google Ads API and AdWords API Forum
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.

import os
import requests
from google.cloud import storage

# Replace the following with your own values
client_secret = 'GOCSPX-3r02jIDeDnq'
scope = 'YOUR_SCOPES'  # e.g. 'https://www.googleapis.com/auth/calendar'

# Update with provided information
client_secret = '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'
redirect_uri = '
'

# Step 1: Redirect the user to the authorization URL
authorization_url = f'https://accounts.google.com/o/oauth2/auth?client_id={client_id}&redirect_uri={redirect_uri}&scope={scope}&response_type=code&access_type=offline'
print('Please go to the following URL to authorize the application:')
print(authorization_url)

# 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_payload = {
    'code': authorization_code,
    'client_id': client_id,
    'client_secret': client_secret,
    'redirect_uri': redirect_uri,
    'grant_type': 'authorization_code'
}
token_response = requests.post(token_url, 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('https://api.example.com', headers=headers)

ac.PNG
ac2.PNG

Google Ads API Forum Advisor

unread,
Apr 24, 2023, 2:05:43 PM4/24/23
to anthony...@gmail.com, adwor...@googlegroups.com

Hi Anthony,

Thanks for reaching out to Google Ads API Support.

With regards to your concern, could you confirm if you are using Google Ads API or Google Cloud BigQuery directly?

In Google Ads API perspective, if you are encountering an error while using API, can you provide us the complete request and response logs with request ID generated as shown in the respective links? We do this to check if there’s an error thrown on your side and we can further investigate. 

You may then send the requested information via the Reply privately to the author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.

However, if you are using Google Cloud BigQuery, then I recommend reaching out to the Google Cloud BigQuery support for further assistance. They can assist you more appropriately regarding these kinds of inquiries.

Links included in this email:


Regards,

Google Logo Google Ads API Team


ref:_00D1U1174p._5004Q2kphaC:ref
Reply all
Reply to author
Forward
0 new messages