我目前正在開發一個簡單的本機Python應用程序來與我的Google日曆交互。爲了做到這一點,我首次使用Google Calendar API,這要歸功於Google Python庫。使用Python的Google日曆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的參考文檔找到的代碼示例,但沒有任何更改。
在此先感謝您的幫助。
你有沒有在https://code.google.com/apis/console的API註冊帳戶? – 2013-02-21 13:00:16
當然可以。我忘了說我已經嘗試了Google文檔中的一些示例代碼,並取得了成功。 – aseure 2013-02-21 13:24:58