我应该使用哪个库来获取访问令牌?

2024-04-19 09:03:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个谷歌登录网页,我想访问用户的数据代表用户,即使他是离线。你知道吗

我正在寻找一个库的建议,我可以使用它来获取access tokenrefresh token,使用客户机发送到服务器的authorization code。你知道吗

我遵循官方指南here
步骤7:将授权代码交换为访问令牌中,作者使用了oauth2client库,该库似乎已被弃用:

Note: oauth2client is now deprecated. No more features will be added to the libraries and the core team is turning down support. We recommend you use google-auth and oauthlib. For more details on the deprecation, see oauth2client deprecation.

所以我看了google-auth

This library provides no support for obtaining user credentials, but does provide limited support for using user credentials.

我还查看了oauthlib,但是有许多页面没有文档记录。你知道吗

我正在使用python3.x和Flask。你知道吗


Tags: andthe用户tokenauthsupportforis
1条回答
网友
1楼 · 发布于 2024-04-19 09:03:14

使用Requests-OAuthlib结束。你知道吗

pip install requests requests_oauthlib

from requests_oauthlib import OAuth2Session

oauth = OAuth2Session(client_id=GOOGLE_CLIENT_ID,
                      scope=GOOGLE_SCOPE,
                      redirect_uri='http://localhost:8000')

token = oauth.fetch_token(token_url=GOOGLE_TOKEN_URL,
                          code=authorization_code,
                          client_secret=GOOGLE_CLIENT_SECRET)

相关问题 更多 >