如何在本地Python代码中打开Goog le OAuth 2.0许可屏幕?

问题描述 投票:0回答:1

如何在我的本地Python代码中使用consent screen获得Google OAuth 2.0授权?

在我的Google Colab笔记本中,我也可轻松完成此操作,例如,访问我的Google表格

from oauth2client.client import GoogleCredentials
from google.colab import auth
import gspread

auth.authenticate_user()
gc = gspread.authorize(GoogleCredentials.get_application_default())

这会在我的浏览器中打开Goog​​le Colab同意屏幕,我会在其中登录我的工作表所在的帐户并获取我为响应提示而粘贴的令牌。

如何在本地Jupyter笔记本或代码中打开我的同意屏幕?是否有上述流程将启动同意屏幕,允许我在那里进行身份验证,收集(临时)令牌,并粘贴它以响应提示的提示?

python google-cloud-platform google-oauth google-colaboratory gspread
1个回答
0
投票

在Colab之外不提供google.colab图书馆。

gspread文档描述了如何通常对库进行身份验证:https://github.com/burnash/gspread#basic-usage

重现相关代码段:

  1. Google Developers Console获取OAuth2凭据
  2. 开始使用gspread: import gspread gc = gspread.authorize(credentials)

大部分工作都是通过链接中描述的云项目创建过程完成的。

© www.soinside.com 2019 - 2024. All rights reserved.