我正在使用PHP中的 google drive API 。首先,我请求一个Auth url并将用户发送到该URL。用户根据需要使用查询字符串中的授权代码授权并重定向到我的URL。接下来,我调用$client->authorize()
并传递查询字符串中的代码。我收到以下错误:
Uncaught exception 'Google_AuthException' with message 'Error fetching OAuth2 access token, message: 'invalid_grant'' in
/home/a5874817/public_html/custom/google/src/auth/Google_OAuth2.php:113
Stack trace:
#0 /home/a5874817/public_html/custom/google/src/Google_Client.php(131): Google_OAuth2->authenticate(Array, '4/jN5JfD_ejozBj...')
#1 /home/a5874817/public_html/custom/docs_reply.php(10): Google_Client->authenticate('4/jN5JfD_ejozBj...')
#2 {main}
thrown in /home/a5874817/public_html/custom/google/src/auth/Google_OAuth2.php on line 113
此帐户之前已授权此应用,但auth网址始终包含access_type = online,并且超过一小时前因此访问令牌已过期。具体可能是导致此错误的原因是什么?
答案 0 :(得分:0)
由于您只有在线访问权限,因此在用完时您将无法刷新新的访问令牌。
如果您想要永久访问权限,请求access_type = offline,并确保存储刷新令牌供以后使用。
答案 1 :(得分:0)
嗯,这个问题已经消失了,但我不记得我所做的很多改变中确切地解决了这个问题。我认为问题在于我的auth url中包含了错误的access_type,或者客户端设置错误。如果其他人有类似的问题,我建议确保范围是正确的,并实际读取所有的auth url,以确保它有意义。