how to get eternal token?

168 views
Skip to first unread message

sprytar....@gmail.com

unread,
Oct 2, 2017, 3:06:14 PM10/2/17
to AdWords API Forum

Hi, The previous developer used the function TargetingIdeaService to get new keywords, based on one old one. 

We have a file with constant settings: adsapi_php.ini.

But today we have error 

Client error: `POST https://www.googleapis.com/oauth2/v4/token` resulted in a `400 Bad Request` response:
{ "error": "invalid_grant",
"error_description": "Bad Request" }

Can I somehow get a long-term token to always get new keywords, do not force the user to give access to the application?

Thanks

sprytar....@gmail.com

unread,
Oct 2, 2017, 3:55:52 PM10/2/17
to AdWords API Forum
I have an idea to keep getting a token, say admin, and store it in the database and update it for all users' requests so that they do not have to confirm application permissions. Is this a good idea?

Bharani Cherukuri (AdWords API Team)

unread,
Oct 2, 2017, 5:19:10 PM10/2/17
to AdWords API Forum
Hello, 

The 'invalid_grant' error is usually noticed when the access token or refresh token is invalid or incorrect. To verify this, you can obtain the access token being used for the request, then pass that through this tokeninfo endpoint to retrieve the token details. Additionally, could you confirm if you're generating the refresh token in every API call? If so, please note that there is a limit of 50 refresh tokens per user per account. If you're trying to generate a refresh token above the specified limit, they will be invalidated. 

This said, the OAuth2TokenRefresher.php provides functionality to retrieve OAuth2 access tokens and handling refreshing the token if it is expired. By default, the client libraries automatically refresh expired access tokens. As for your second concern, you will have to accept the prompt manually once for every user. Let me know if you have any other questions.

Thanks,
Bharani, AdWords API Team
Reply all
Reply to author
Forward
0 new messages