serpbear: Error Saving the Google Ads Refresh Token

When trying to authenticate with Google Ads account, getting this: “Error Saving the Google Ads Refresh Token. Please Try Again!”. Container volume is writable. Logs are as below:

[0] [Error] Getting Google Ads Refresh Token!
[0] error : GaxiosError: invalid_grant
[0]     at Gaxios._request (/app/node_modules/gaxios/build/src/gaxios.js:142:23)
[0]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[0]     at async OAuth2Client.getTokenAsync (/app/node_modules/google-auth-library/build/src/auth/oauth2client.js:137:21)
[0]     at async getAdwordsRefreshToken (/app/.next/server/pages/api/adwords.js:143:27)
[0]     at async Object.apiResolver (/app/node_modules/next/dist/server/api-utils/node.js:366:9)
[0]     at async NextNodeServer.runApi (/app/node_modules/next/dist/server/next-server.js:481:9)
[0]     at async Object.fn (/app/node_modules/next/dist/server/next-server.js:741:37)
[0]     at async Router.execute (/app/node_modules/next/dist/server/router.js:252:36)
[0]     at async NextNodeServer.run (/app/node_modules/next/dist/server/base-server.js:365:29)
[0]     at async NextNodeServer.handleRequest (/app/node_modules/next/dist/server/base-server.js:303:20) {
[0]   config: {
[0]     method: 'POST',
[0]     url: 'https://oauth2.googleapis.com/token',
[0]     data: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
[0]     headers: {
[0]       'Content-Type': 'application/x-www-form-urlencoded',
[0]       'User-Agent': 'google-api-nodejs-client/9.6.3',
[0]       'x-goog-api-client': 'gl-node/20.11.1'
[0]     },
[0]     paramsSerializer: [Function: paramsSerializer],
[0]     body: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
[0]     validateStatus: [Function: validateStatus],
[0]     responseType: 'unknown',
[0]     errorRedactor: [Function: defaultErrorRedactor]
[0]   },
[0]   response: {
[0]     config: {
[0]       method: 'POST',
[0]       url: 'https://oauth2.googleapis.com/token',
[0]       data: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
[0]       headers: [Object],
[0]       paramsSerializer: [Function: paramsSerializer],
[0]       body: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
[0]       validateStatus: [Function: validateStatus],
[0]       responseType: 'unknown',
[0]       errorRedactor: [Function: defaultErrorRedactor]
[0]     },
[0]     data: { error: 'invalid_grant', error_description: 'Bad Request' },
[0]     headers: {
[0]       'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000',
[0]       'cache-control': 'no-cache, no-store, max-age=0, must-revalidate',
[0]       'content-encoding': 'gzip',
[0]       'content-type': 'application/json; charset=utf-8',
[0]       date: 'Wed, 06 Mar 2024 10:30:44 GMT',
[0]       expires: 'Mon, 01 Jan 1990 00:00:00 GMT',
[0]       pragma: 'no-cache',
[0]       server: 'scaffolding on HTTPServer2',
[0]       'transfer-encoding': 'chunked',
[0]       vary: 'Origin, X-Origin, Referer',
[0]       'x-content-type-options': 'nosniff',
[0]       'x-frame-options': 'SAMEORIGIN',
[0]       'x-xss-protection': '0'
[0]     },
[0]     status: 400,
[0]     statusText: 'Bad Request',
[0]     request: { responseURL: 'https://oauth2.googleapis.com/token' }
[0]   },
[0]   error: undefined,
[0]   status: 400,
[0]   [Symbol(gaxios-gaxios-error)]: '6.3.0'
[0] }

About this issue

  • Original URL
  • State: closed
  • Created 4 months ago
  • Reactions: 2
  • Comments: 57 (21 by maintainers)

Commits related to this issue

Most upvoted comments

I have written numerous OAuth2 integrations for various APIs, and we have never had to make any modifications to connect from localhost or production. I’ll have a look at your code when i find time today.

I captured the whole process client id and client secret creation process. Please watch the video and see if you are doing anything wrong: https://erevanto.sirv.com/videos/serpbear_adwords_step1.mp4

I did everything exactly like in the video but still having the error. I will try it with a fresh Google account now.

@bananasplit8041 do you run it on localhost?

no i run it on fly.io!

now I’m failing at the dev token: ] [ERROR] Google Ads Response : The developer token is only approved for use with test accounts. To access non-test accounts, apply for Basic or Standard access.

EDIT: now its working! need to click on https://ads.google.com/nav/selectaccount?sf=mt Add account and copy the ID

wow, magic! really like this tool!!

Turns out it was a bug specific to how Nextjs handles the NEXT_PUBLIC_APP_URL variable. #17641 When the app is built, it actually uses the value that was set on the built machine which means it’s almost hardcoded. This only happens with docker installation. In any case, had to workaround this by grabbing the domain name from the request header and building the redirect URL using that.

So, those who are having this issue, update to version 2.0.2, and the issue should be fixed.

That’s very strange. All your settings are correct. I only tried the integration with localhost and not with an actual domain. However, another user mentioned, that it worked fine for them with an actual domain. I will run some tests with an actual domain and report back.

All good man, just letting you know because we love this project and want to see it go places!!!.. Just take it as a bug report 😃 hope it helps for further development

I missed to publish the application, this step was missing at https://docs.serpbear.com/miscellaneous/integrate-google-ads and I set the NEXT_PUBLIC_APP_URL on fly.io and now it’s working! !

You need 2 AdWords accounts, a test account, and a manager account.