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?

Tag:google-ads-api, google-ad-manager, c#, postman, restsharp

9 comments.

  1. fatima Ajij

    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.

    1. IanS

      An app should not need to be "published" in order for the refresh token to persist. The refresh token should last "forever" (as this is what is used to fetch the access token)

    2. IanS

      If this solution is true, this is surely a bug that Google need to fix?

    3. Linda Lawton - DaImTo

      @IanS if you already knew this answer existed why did you ask a new question and answer it again?

    4. IanS

      @DaImTo Three reasons: (1) My question refers to different programming languages and tools; (2) I had already written my question before stumbling upon this as one potential solution; (3) the jury is still out: the above is not marked as correct, and I am not yet sure if it even works. It does not make sense to me, nor is it documented, that a token that is supposed to last forever would frequently expire when testing.

    5. Linda Lawton - DaImTo

      Tokens generated through the Oauth2 playground only last a few weeks they are not intended to be permanent. You should be using your own code to create a refresh token and submitting your project for verification.

  2. bad_coder

    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.

  3. Brookie_C

    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.

    1. Stefan Stojkovski

      You can just reauthorize your application by deleting stored credentials in $user\.credentials\.

Add a new comment.