【问题标题】:Google blogger api and expired secret key.谷歌博客 API 和过期的密钥。
【发布时间】: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


【解决方案1】:

如Google’s OAuth 2.0 documentation 中所述,您应该在身份验证流程中收到一个刷新令牌。您应该将该令牌存储在某个地方,然后在必要时使用它来获取新的访问令牌。

用刷新令牌交换新访问令牌的具体过程取决于您使用的 OAuth 客户端库。例如,在 Signet(Google 的 Ruby OAuth 库)中,它是作为 fetch_access_token 的一部分完成的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-25
    • 1970-01-01
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多