Mic*_*inh 2 python django youtube-api oauth-2.0
尝试构建 Google API 资源时我收到一条错误消息
'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/')
Run Code Online (Sandbox Code Playgroud)
点冻结:
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
Run Code Online (Sandbox Code Playgroud)
你使用flow.fetch_token方法不对。它的返回值不是一个credentials对象,而是一组标记。该文档解释说您不应该使用它:
返回获取到的token。通常,您不会使用此函数的返回值,而是使用 和
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3561 次 |
| 最近记录: |