我正在尝试获取登录用户的G +个人资料。这是我的代码。
@app.route('/Home')
def home():
"""Home Route"""
session['state'] = state
if 'credentials' not in flask.session:
return flask.redirect(flask.url_for('oauth2callback'))
credentials = client.OAuth2Credentials.from_json(flask.session['credentials'])
if credentials.access_token_expired:
return flask.redirect(flask.url_for('oauth2callback'))
else:
http_auth = credentials.authorize(httplib2.Http())
plus_service = discovery.build('plus', 'v1', http_auth)
people_document = plus_service.people().get(userId=users.get_current_user().user_id()).execute()
#files = drive_service.files().list().execute()
return json.dumps(people_document)
@app.route('/oauth2callback')
def oauth2callback():
flow = client.flow_from_clientsecrets(
'client_secrets.json',
scope='https://www.googleapis.com/auth/plus.me',
redirect_uri=flask.url_for('oauth2callback', _external=True),)
if 'code' not in flask.request.args:
auth_uri = flow.step1_get_authorize_url()
return flask.redirect(auth_uri)
else:
auth_code = flask.request.args.get('code')
credentials = flow.step2_exchange(auth_code)
flask.session['credentials'] = credentials.to_json()
return flask.redirect(flask.url_for('home'))
当我点击URL / Home时,出现以下错误。
WARNING 2016-04-20 09:50:01,331 util.py:134] build() takes at most 2 positional arguments (3 given)
INFO 2016-04-20 09:50:01,392 discovery.py:817] URL being requested: GET https://www.googleapis.com/plus/v1/people/xxxxx?alt=json
WARNING 2016-04-20 09:50:01,395 urlfetch_stub.py:540] Stripped prohibited headers from URLFetch request: ['content-length']
ERROR 2016-04-20 09:50:04,242 wsgi.py:279]
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 267, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "/Users/vinay/App-Engine/Rainbow/gaenv/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/vinay/App-Engine/Rainbow/gaenv/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/vinay/App-Engine/Rainbow/gaenv/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/vinay/App-Engine/Rainbow/gaenv/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/Users/vinay/App-Engine/Rainbow/gaenv/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/vinay/App-Engine/Rainbow/gaenv/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/vinay/App-Engine/Rainbow/gaenv/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/vinay/App-Engine/Rainbow/gaenv/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/vinay/App-Engine/Rainbow/mainsite/__init__.py", line 61, in home
people_document = plus_service.people().get(userId=users.get_current_user().user_id()).execute()
File "/Users/vinay/App-Engine/Rainbow/gaenv/oauth2client/util.py", line 135, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Users/vinay/App-Engine/Rainbow/gaenv/googleapiclient/http.py", line 760, in execute
raise HttpError(resp, content, uri=self.uri)
HttpError: <HttpError 403 when requesting https://www.googleapis.com/plus/v1/people/xxxx?alt=json returned "Insufficient Permission">
INFO 2016-04-20 09:50:04,386 module.py:787] default: "GET /Home HTTP/1.1" 500 -