Google API PHP offline access, “invalid_grant: Code was already redeemed”

后端 未结 1 509
小蘑菇
小蘑菇 2020-12-24 09:28

How to authorize a Google Client permanently until the user revokes authorization?

I am trying to make an app that connects to Google Calendar. It h

相关标签:
1条回答
  • 2020-12-24 10:05

    There are three types of codes or tokens Googles Authentcation server returns.

    1. Authentication code
    2. Access token
    3. Refresh token.

    Authentication code

    When a user clicks on the Authentcation form and grants your application access. Google returns to you an Authentcation code. You should take this code and exchange it for an Access token and a refresh token. This code is only used once if you try and use it again you will get an error message.

    invalid_grant: Code was already redeemed.

    Access token

    Access tokens are used to access the APIs this token should be sent along with every request you make. Access tokens are short lived they work for an hour and then they stop working

    Refresh token

    Refresh tokens should be saved on your server some place. Once the access token expires you can use the refresh token to get a new access token.

    Your problem is that you are saving the authentication code which is of no use to you. You need to find the refresh token and save that.

    0 讨论(0)
提交回复
热议问题