有人可以给我一个关于如何让 Google Calendar API v3 与 Python 客户端一起工作的明确解释吗?具体来说,最初的 OAuth 阶段让我非常困惑。我需要做的就是访问我自己的日历,阅读它并对其进行更改。Google 提供了此代码来配置我的应用程序:
import gflags
import httplib2
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run
FLAGS = gflags.FLAGS
# Set up a Flow object to be used if we need to authenticate. This
# sample uses OAuth 2.0, and we set up the OAuth2WebServerFlow with
# the information it needs to authenticate. Note that it is called
# the Web Server Flow, but it can also handle the flow for native
# applications
# The client_id and client_secret are copied from the API Access tab on
# the Google APIs Console
FLOW = OAuth2WebServerFlow(
client_id='YOUR_CLIENT_ID',
client_secret='YOUR_CLIENT_SECRET',
scope='https://www.googleapis.com/auth/calendar',
user_agent='YOUR_APPLICATION_NAME/YOUR_APPLICATION_VERSION')
# To disable the local server feature, uncomment the following line:
# FLAGS.auth_local_webserver = False
# If the Credentials don't exist or are invalid, run through the native client
# flow. The Storage object will ensure that if successful the good
# Credentials will get written back to a file.
storage = Storage('calendar.dat')
credentials = storage.get()
if credentials is None or credentials.invalid == True:
credentials = run(FLOW, storage)
# Create an httplib2.Http object to handle our HTTP requests and authorize it
# with our good Credentials.
http = httplib2.Http()
http = credentials.authorize(http)
# Build a service object for interacting with the API. Visit
# the Google APIs Console
# to get a developerKey for your own application.
service = build(serviceName='calendar', version='v3', http=http,
developerKey='YOUR_DEVELOPER_KEY')
但是(a)这对我来说完全没有意义;评论解释很糟糕,而且(b)我不知道在变量中放什么。我已经在 Google 上注册了我的程序并注册了一个服务帐户密钥。但给我的只是一个要下载的加密密钥文件和一个客户端 ID。我不知道什么是“developerKey”,或者什么是“client_secret”?那是关键吗?如果是,我如何获得它,因为它实际上包含在加密文件中?最后,考虑到我使用 API 的相对简单的目标(即,它不是多用户、多访问操作),有没有更简单的方法可以做到这一点?谢谢。