从承载类型令牌获取Google OAuth2凭据或刷新令牌?

2024-06-26 05:07:17 发布

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

我使用pythonggoogleapi客户机库来处理从前端使用google的平台.js图书馆。在

令牌的验证很容易通过调用

google.oauth2.id_token.verify_oauth2_token(
  request.POST['bearer_token'],
  google.auth.transport.requests.Request(),
  client_id )

现在我想访问用户的google驱动器(完全访问)。到目前为止,我所理解的是,要构建服务对象,我们需要像这样的credentials对象。在

^{pr2}$

在这一点上我只有一个持票人代币。如何将其转换为凭据以便访问驱动器API?在


Tags: 对象tokenid客户图书馆requestgooglejs
1条回答
网友
1楼 · 发布于 2024-06-26 05:07:17

凭据对象来自“谷歌.oauth2.credentials”,要设置凭据对象,您需要知道某些值:

  • 代币
  • 刷新令牌
  • 令牌URI
  • 客户端Id
  • 客户机密

以下是如何访问用户的驱动器:

credentials = Credentials(
            token=token,
            refresh_token=refresh_token,
            token_uri="https://www.googleapis.com/oauth2/v3/token", 
            client_id=client_id,
            client_secret=client_secret,
        )

drive_service = build('drive', "v3", credentials=credentials)

你可以试着把你的“持有者令牌”设为“令牌”,但我不确定它是否有效。以下是“Credential”对象https://google-auth.readthedocs.io/en/latest/reference/google.oauth2.credentials.html的文档

相关问题 更多 >