我目前正在开发一个简单的原生 Python 应用程序来与我的 Google 日历交互。为了做到这一点,感谢 Google Python 库,我第一次使用了 Google Calendar API。
但是,尽管有文档,但在我的日历中插入一个新事件时,我还是陷入了僵局。这是我用于连接和执行请求的代码的一部分:
import sys
...
import httplib2
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import AccessTokenRefreshError
from oauth2client.client import flow_from_clientsecrets
from oauth2client.tools import run
...
flow = flow_from_clientsecrets('client_secrets.json',
scope='https://www.googleapis.com/auth/calendar',
redirect_uri='http://localhost')
storage = Storage('credentials.dat')
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = run(flow, storage)
http = httplib2.Http()
http = credentials.authorize(http)
service = build('calendar', 'v3', http=http)
try:
event = {
"start": "2013-02-20T09:00:00.000+01:00",
"end": "2013-02-20T11:00:00.000+01:00",
"summary": "New event",
"location": "Paris, FRANCE"
}
service.events().insert(calendarId='primary', body=event).execute()
print "END"
except AccessTokenRefreshError:
print ('Credentials have been revoked')
一旦执行,这就是我得到的:
{
"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."
}
}
到目前为止,我已经尝试了很多东西,包括我在 Google Calendar API 的参考文档中找到的所有代码示例,但没有任何改变。
在此先感谢您的帮助。