Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
niclaz79
Partner - Creator III
Partner - Creator III

Issue with authorization key for Google Business

Hi, I'm trying to run the following script in order to refresh my authorization key for a Google Business account. I can use the playground to obtain it manually, but obviously I need to be able to automate it in Qlik Sense.

I have changed the client id, client secret and refresh token secrets for this post, but there are real values there in the actual code

SET vClient_id = 'client id';
SET vClient_secret = 'client secret';

SET vRefresh_token = 'refresh token';

LET vRequestBody ='';
LET vRequestBody = vRequestBody & 'grant_type=refresh_token';
LET vRequestBody = vRequestBody & '&client_id=' & '$(vClient_id)';
LET vRequestBody = vRequestBody & '&client_secret=' & '$(vClient_secret)';
LET vRequestBody = vRequestBody & '&refresh_token=' & '$(vRefresh_token)';

LIB CONNECT TO 'Google Authorization';

access_token:
SQL SELECT
"access_token",
"token_type",
"expires_in"
FROM JSON (wrap on) "root"
WITH CONNECTION (
URL "https://accounts.google.com/o/oauth2/token",
HTTPHEADER "Content-Type" "application/x-www-form-urlencoded",
BODY "$(vRequestBody)"
)
;

LET vAccessToken = peek('access_token',0,'access_token');

I get the following error message:

HTTP protocol error 400 (Bad Request): { "error": "invalid_grant", "error_description": "Bad Request" }

I feel there could be a setting on the Google Business side that I need to make, but I cannot find any resources that tells me what that is. And as I said, it works fine in playground to get a new authorization code.

2 Solutions

Accepted Solutions
gustavgager
Partner - Creator II
Partner - Creator II

"Invalid Grant" seems to be a very generic error but mostly its related to tokens and access permissions. It can be as simple as the user blocking the access or that the tokens themselves are old. There is a great post about this issue here:

https://blog.timekit.io/google-oauth-invalid-grant-nightmare-and-how-to-fix-it-9f4efaf1da35#.eqa5iwb...

View solution in original post

gustavgager
Partner - Creator II
Partner - Creator II

Maybe you could try setting up some new credentials on your own account? You might also have to enable the specific APIs you want to use.

View solution in original post

3 Replies
gustavgager
Partner - Creator II
Partner - Creator II

"Invalid Grant" seems to be a very generic error but mostly its related to tokens and access permissions. It can be as simple as the user blocking the access or that the tokens themselves are old. There is a great post about this issue here:

https://blog.timekit.io/google-oauth-invalid-grant-nightmare-and-how-to-fix-it-9f4efaf1da35#.eqa5iwb...

niclaz79
Partner - Creator III
Partner - Creator III
Author

I've read that one and could not figure out anything that was incorrect in the project settings or otherwise unfortunately.

gustavgager
Partner - Creator II
Partner - Creator II

Maybe you could try setting up some new credentials on your own account? You might also have to enable the specific APIs you want to use.