谷歌API离线访问

Google API offline access

本文关键字:访问 离线 API 谷歌      更新时间:2023-09-26

我已经在Google控制台中启用了适当的API。这不是问题所在。我需要写一个node js应用程序访问用户的数据时,他们是离线的。我已经设法实现了oauth2授权,并获得了一个refresh_token,我后来用它来获得一个新的访问令牌。

现在我已经到达了实际访问API本身的点。我有这个URL的工作完美当调用curl从shell:

curl https://www.googleapis.com/calendar/v3/calendars/primary/events?access_token=mytoken

它返回一个包含所有事件的JSON,并且持续工作。不管我叫多少遍。

然而完全相同的URL在粘贴到任何浏览器的地址栏时都失败了。

以下是Google发来的回复:

{
"error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
    "extendedHelp": "https://code.google.com/apis/console"
   }
  ],
  "code": 403,
  "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
 }
}

当在node js中使用"request"模块从服务器端调用时,也会出现相同的错误,如下所示:

request('https://www.googleapis.com/calendar/v3/calendars/primary/events?token=mytoken', function(err, httpResponse, body){ /* ..print body or fail.. */ }

所有与google api相关的搜索都指向(几乎)相同的页面。

有人知道我做错了什么吗?

使用Google提出的替代方法,我在shell和node上都获得了一致的结果:我已经删除了access_token GET查询参数我正在添加以下标题:- "授权:持有者ACCESS_TOKEN_HERE"

。谢谢你的评论