日历 API 响应“403:超出每日限制” - 谷歌浏览器扩展
我从一个小应用程序开始,向我们的开发团队展示一些从不同来源收集的相关信息。就像谷歌日历、我们的项目后台、openarena 服务器日志等。
我从一个 Web 应用程序开始,但后来决定将项目切换到 chrome 扩展。现在我已经使用 V3 Javascript(alpha) 客户端库集成并运行了 google 日历。这不再起作用,因为我必须更改 OAUTH 舞蹈,从用于网络应用程序的舞蹈,更改为用于打包/安装应用程序的舞蹈。
为此,我按照教程进行操作(这是我的第一个扩展。)http://code.google。 com/chrome/extensions/tut_oauth.html 并让 OAUTH 舞蹈再次工作。现在我尝试使用教程中的signedRequest-Methode从google api请求我的日历数据,但总是收到响应“超出每日限制。请注册”(Api控制台显示我没有执行任何请求) 。
也许有人知道我在这里做错了什么,因为我尝试了我能想到的一切。预先感谢,弗洛里安
代码 - manifest.json:
{
"name": "MIS",
"version": "0.1",
"description": "Monitor Information System",
"background_page": "background.html",
"browser_action": {
"default_icon": "img/mis/icon.png",
"default_title": "Mis"
},
"permissions": [
"tabs",
"https://www.googleapis.com/",
"https://www.google.com/"]
}
background.html:
...
oauth = ChromeExOAuth.initBackgroundPage
({
'request_url':'https://www.google.com/accounts/OAuthGetRequestToken',
'authorize_url':'https://www.google.com/accounts/OAuthAuthorizeToken',
'access_url':'https://www.google.com/accounts/OAuthGetAccessToken',
'consumer_key': 'anonymous',
'consumer_secret': 'anonymous',
'scope': 'https://www.googleapis.com/auth/calendar',
'app_name': 'Mis'
});
...
main.html 方法调用:
function performCalendarEventsRequest(calendarId)
{
var requestUrl = 'https://www.googleapis.com/calendar/v3/calendars/'+calendarId+'/events';
var request = {
'method': 'GET',
'headers': {
'GData-Version': '3.0',
'Content-Type': 'application/atom+xml'
},
'parameters': {
'alt': 'json'
},
'body': 'Data to send'
};
oauth.sendSignedRequest(requestUrl, calendarEventsRequestCallback, request);
}
I started with an little application for showing some relevant information to our developer team, which is collected from different sources. Like google calendar, our project backoffice, an openarena server-logs etc.
I started with an web application, but then decided to switch the project to an chrome extension. Now i already had the google calendar integration up and running using the V3 Javascript(alpha) Client-Lib. This wasn't working anymore because i had to change the OAUTH dance, from the one for web-apps, to the one for packaged/installed apps.
For this i followed the tutorial (It's my first extension.) http://code.google.com/chrome/extensions/tut_oauth.html and got the OAUTH dance working again. Now i'am trying to request my calendar-data from the google api using the signedRequest-Methode from the tutorial, but alway receive the response "Daily Limit Exceeded. Please sign up" (Api Console shows i haven't performed any request).
Maybe someone has an idea what i am doing wrong here, because i tried everthing i could think about. Thanks in advance, Florian
Code -
manifest.json:
{
"name": "MIS",
"version": "0.1",
"description": "Monitor Information System",
"background_page": "background.html",
"browser_action": {
"default_icon": "img/mis/icon.png",
"default_title": "Mis"
},
"permissions": [
"tabs",
"https://www.googleapis.com/",
"https://www.google.com/"]
}
background.html:
...
oauth = ChromeExOAuth.initBackgroundPage
({
'request_url':'https://www.google.com/accounts/OAuthGetRequestToken',
'authorize_url':'https://www.google.com/accounts/OAuthAuthorizeToken',
'access_url':'https://www.google.com/accounts/OAuthGetAccessToken',
'consumer_key': 'anonymous',
'consumer_secret': 'anonymous',
'scope': 'https://www.googleapis.com/auth/calendar',
'app_name': 'Mis'
});
...
main.html Methode call:
function performCalendarEventsRequest(calendarId)
{
var requestUrl = 'https://www.googleapis.com/calendar/v3/calendars/'+calendarId+'/events';
var request = {
'method': 'GET',
'headers': {
'GData-Version': '3.0',
'Content-Type': 'application/atom+xml'
},
'parameters': {
'alt': 'json'
},
'body': 'Data to send'
};
oauth.sendSignedRequest(requestUrl, calendarEventsRequestCallback, request);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您的消费者密钥和秘密都设置为
匿名
,因此您不会以任何方式识别您的应用程序。您可以分别将它们替换为客户端 ID 和客户端密钥值,这些值可以在 API 控制台,或者您可以使用附加
key
参数传递 API 密钥(位于同一页面的身份验证令牌下)。这对于大多数 Google API 来说都是一样的。
来源: http://code.google。 com/apis/calendar/v3/using.html#APIKey
Since your consumer key and secret are both set as
anonymous
you are not identifying your application in any way.You can either replace these with the Client ID and Client secret values respectively, which can be found on the API Access tab on your projects page in the API Console, or you can pass the API key (found just under the auth tokens on the same page) using an additional
key
parameter.This is the same for most Google APIs.
Source: http://code.google.com/apis/calendar/v3/using.html#APIKey
我知道这是一个老问题,但我使用 API 的 PHP 实现(测试版)(2016-01-06)陷入了同样的错误,因为我最初认为
setAuthConfigFile
就是全部需要:该错误实际上并不是由于请求的“每日限制”造成的,而是由于我(Google 帐户的所有者)没有明确授予对日历的访问权限。具体方法如下:
authenticate($code)
方法中,瞧,不再有 403: Daily Limit Exceeded 错误。为此,只需在调用服务之前使用以下几行:
但是,这将允许一次性访问日历。如果你尝试两次,你会得到:
这意味着需要令牌才能使用重新兑换的代码重新访问日历。该令牌由
authenticate
方法返回,并可以通过setAccessToken
方法分配给客户端:目标是重复重用该访问令牌(隐式地也重用已兑换的代码) )并且仅在令牌过期时调用
refreshToken
。 Google 的快速入门会创建一个用于存储此令牌的特定文件 (calendar- php-quickstart.json),并且仅当在该文件中找不到令牌时才使用authenticate
方法。即,setAccessToken
是后续请求中需要使用的唯一客户端身份验证方法(除了setAuthConfigFile
)。我只是通过阅读才完全理解了这个 OAuth 2.0 逻辑这些错误,既然这个问题已经吸引了很多人,也许这可能会帮助其他人......
I know this is an old question but I was stuck in the same error using the PHP implementation (Beta) of the API (2016-01-06), because I initially thought the
setAuthConfigFile
was all it was needed:The error was not really due to a "daily limit" of requests but to the fact that I (owner of the Google account) hadn't explicitly given access permissions to the calendar. This is how to do it:
createAuthUrl()
method (which can be invoked before calling the service);authenticate($code)
method and voilá, no more 403: Daily Limit Exceeded errors.For doing this, just use the following lines before invoking the service:
However, this will allow a one time access to the calendar. If you try this twice, you get:
Meaning that a token is needed to reaccess the calendar with the reedemed code. This token is returned by the
authenticate
method and can be assigned to the client through thesetAccessToken
method:The goal is to reuse that access token repeatedly (implicitly also reusing the redeemed code) and only invoke a
refreshToken
when the token expires. Google's quickstart creates a specific file for storing this token (calendar-php-quickstart.json) and only uses theauthenticate
method when the token is not found in that file. I.e. thesetAccessToken
is the only Client authentication method (besides thesetAuthConfigFile
) that needs to be used in subsequent requests.I only fully understood this OAuth 2.0 logic by going through these errors and since this question attracted so many people already, perhaps this may help others...