Google-api-php Refresh Token returns invalid_grant

前端 未结 5 674
离开以前
离开以前 2020-12-31 17:58

I\'ve nearly searched every result of the first page of google for this. But can\'t seem to find the answer. I\'m working with a refresh_token by Google\'s API and receiving

相关标签:
5条回答
  • 2020-12-31 18:09

    The function that worked for me is as follows

    $client->setAccessType("refresh_token");

    0 讨论(0)
  • 2020-12-31 18:12

    I ran into something similar and the problem for me was my system clock (inside the Docker VM where I was running the code) was not synchronized with the real time. So you are requesting a token with a created date too far in the past or future, which OAuth is rejecting.

    I was tipped of by the report here.

    0 讨论(0)
  • 2020-12-31 18:15

    You'll get an "invalid_grant" error if you try to refresh when the token isn't expired.

    Instead of this:

    $client->refreshToken(file_get_contents('../_config/refreshtoken.conf'));
    

    Use this:

    $client->setAccessToken(file_get_contents('../_config/refreshtoken.conf'));
    

    Once your token expires you refresh should work.

    0 讨论(0)
  • 2020-12-31 18:18

    The invalid_grant means either means that the authorization code has already been used (available in $GET['code']) or the type of application configured in the Google APIs Console is invalid.

    Make sure you select "Web Application" when registering your app in the Google APIs Console.

    0 讨论(0)
  • 2020-12-31 18:28

    Before Authenticate, there must be something like:

    $client->grantType("refresh_token")
    
    0 讨论(0)
提交回复
热议问题