在试图构建Google资源时,我收到一个错误信息
'OAuth2Token' object has no attribute 'authorize'
我在这里看到一个解决方案正在安装google-auth-httplib2,但是我已经安装了它,但仍然遇到了错误。
class Oauth2CallbackView(View):
def get(self, request, *args, **kwargs):
flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
CLIENT_SECRETS_FILE, scopes=SCOPES)
flow.redirect_uri = 'http://127.0.0.1:8000/profiles/oauth2callback/'
credentials = flow.fetch_token(code=self.request.GET.get('code'))
b = build(API_SERVICE_NAME, API_VERSION, credentials=credentials)
return redirect('http://127.0.0.1:8000/profiles/')PipFreeze:
cachetools==3.1.1
certifi==2019.3.9
chardet==3.0.4
Click==7.0
defusedxml==0.6.0
dj-database-url==0.5.0
Django==2.2.1
django-allauth==0.39.1
django-appconf==1.0.3
django-heroku==0.3.1
django-image-cropping==1.2.0
django-multiselectfield==0.1.8
easy-thumbnails==2.6
Flask==1.0.3
google-api-python-client==1.7.9
google-auth==1.6.3
google-auth-httplib2==0.0.3
google-auth-oauthlib==0.3.0
gunicorn==19.9.0
httplib2==0.12.3
idna==2.8
itsdangerous==1.1.0
Jinja2==2.10.1
jsonpickle==1.2
MarkupSafe==1.1.1
oauthlib==3.0.1
Pillow==6.0.0
psycopg2==2.8.2
pyasn1==0.4.5
pyasn1-modules==0.2.5
python-dotenv==0.10.2
python3-openid==3.1.0
pytz==2019.1
requests==2.22.0发布于 2019-06-09 04:39:42
你使用flow.fetch_token不正确。它的返回值不是credentials对象,而是一组令牌。文档解释说,您不应该使用这个:
返回所获得的令牌。通常,您将不使用此函数的返回值,而是使用
credentials()获取Credentials实例。
你需要做的是这样的事情:
flow.fetch_token(code=self.request.GET.get('code'))
# The credentials are available in flow.credentials, not the return value
b = build(API_SERVICE_NAME, API_VERSION, credentials=flow.credentials)https://stackoverflow.com/questions/56509744
复制相似问题