fatima Ajij
fatima Ajij

Reputation: 182

Token has expired or revoked - Google Ads

Hi I have been using rest methods to integrate Google Ads API in C#. Everything seemed to be working fine but all of sudden I started getting 400 response with the error message.

{
    "error": "invalid_grant",
    "error_description": "Token has been expired or revoked."
}

As mentioned above that I am not using client library but instead using restsharp and testing all my end points using postman also.

Any reason why it is happening? My refresh token is also valid. I have been using this for one week. I have also not reached to the limit of refresh token as I have only generated refresh token 3 to 4 times when I was trying to set up the accounts.

I believe the validity of refresh token is life long then why it is happening?

Upvotes: 6

Views: 6174

Answers (3)

Brookie_C
Brookie_C

Reputation: 437

An alternative method is to re-new your Authentication Token. You'll first need to head over to "Credentials" at https://console.cloud.google.com/ .

After you hover over to your project, you should see a edit icon on the right most, click that. Once you enter that you will see the option: "Reset Secret".

After your reset is complete, make sure to save the project.

Then you will have to hover back to your project and click on the download icon on the right most. This will have you download the JSON secret token.

Replace that token and make sure to delete any other token related file such as "pickle_token" from your repository.

After you have followed all your steps, it may prompt you to re-login through google. And you are all set.

Keep in mind, the token expires after 7 days, if your project is in "testing" mode.

Upvotes: 3

Lost Brown
Lost Brown

Reputation: 41

I have file called StoredCredential, in my Java project, if you have something similar, you can try to delete StoredCredential file and after rerun your code.

Upvotes: 4

fatima Ajij
fatima Ajij

Reputation: 182

I solved the problem by generating new refresh token using playground. The reason it expired because the publishing status of OAuth consent screen of my project was on testing mode.

If you are integrating an API, you need to apply publishing status for production to avoid manual generation of refresh tokens when it expires.

enter image description here

Upvotes: 6

Related Questions