【发布时间】:2017-05-26 01:54:06
【问题描述】:
我已经设法使用 google api 和 oauth 在我的博客中添加了一些帖子,但遇到了一些问题。我已经尝试了几天或几周来找到最好的问题,我相信我已经隔离了这个问题。显然密钥只能工作一小时。但在这一行一个小时后:
$service->blogs->getByUrl("theurlofmyblog.blogspot.com");
我收到此错误:
Google_Service_Exception in REST.php line 118:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
论坛上的一些专家建议必须去这个地址https://developers.google.com/oauthplayground/ 并获得一个referesh 令牌。但是没有人提到我们应该如何使用那个令牌。我把它放在json文件中吗?一定有这样的——请不要笑,这应该是suedo代码——:
if(the key is expired)
use my referesh key and get me another key
有什么经验吗?
【问题讨论】:
-
oauthplayground 是 Google 的 Oauth2 测试环境,您可以在其中测试您的授权流程。如果访问令牌在一小时内过期,那么您可以使用“refresh_token”获取新的令牌(如果您有的话)。您可以从初始授权响应中获取它。如果您没有,那么您只需再次授权即可获得新的访问令牌。您正在使用什么赠款流程?
标签: oauth google-api