[英]How do I open a Google OAuth 2.0 consent screen in a local Python code?
How do I get Google OAuth 2.0 authorization using a consent screen in my local Python code? 如何使用本地Python代码中的同意屏幕获取Google OAuth 2.0授权?
In my Google Colab notebook, I can easily accomplish this too, for example, access my Google Sheets, with 在我的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())
which opens the Google Colab consent screen in my browser, where I log in to the account where my sheet is located and get a token that I paste in response to a prompt. 这会在我的浏览器中打开Google Colab同意屏幕,我会在其中登录我的工作表所在的帐户并获取我为响应提示而粘贴的令牌。
How do I open my consent screen in a local Jupyter notebook or code? 如何在本地Jupyter笔记本或代码中打开我的同意屏幕? Is there an equivalent to the above flow that will launch the consent screen, allow me to authenticate there, collect a (temporary) token, and paste it in response to a presented prompt?
是否有上述流程将启动同意屏幕,允许我在那里进行身份验证,收集(临时)令牌,并粘贴它以响应提示的提示?
google.colab
libraries aren't available outside of Colab. google.colab
库在Colab之外是不可用的。
The gspread
docs have a description for how to authenticate with the library generally: https://github.com/burnash/gspread#basic-usage gspread
文档描述了如何通常对库进行身份验证: https : //github.com/burnash/gspread#basic-usage
Reproducing the relevant snippet: 重现相关代码段:
Start using gspread: 开始使用gspread:
import gspread gc = gspread.authorize(credentials)
Most of the work is going through the cloud project creation process described in the link. 大部分工作都是通过链接中描述的云项目创建过程完成的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.