我有一个Django 1.10项目,我必须向Google APIs发出GET / POST请求。
我已成功通过以下代码中的Google OAuth 2.0授权流程:
def a_oauth2(request):
flow = client.flow_from_clientsecrets('client_secrets.json',
scope=...,
redirect_uri=)
flow.params['access_type'] = 'offline' # offline access
flow.params['include_granted_scopes'] = 'true' # incremental auth
if 'code' not in request.GET:
auth_uri = flow.step1_get_authorize_url()
return HttpResponseRedirect(auth_uri)
else:
auth_code = request.GET['code']
credentials = flow.step2_exchange(auth_code)
http_auth = credentials.authorize(httplib2.Http())
这就是我被困的地方。我现在的目标是导出Google云端硬盘文档。问题是,如何检索OAuth令牌并将其传递给respective GET request? discovery.build(...)
方法如何适应故事?