简体   繁体   English

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

[英]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. 这会在我的浏览器中打开Goog​​le 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: 重现相关代码段:

  1. Obtain OAuth2 credentials from Google Developers Console Google Developers Console获取OAuth2凭据
  2. 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.

相关问题 如何在Google App Engine Python中创建同意屏幕 - How do I create a consent screen in Google App Engine Python 带有Python的Google Oauth2.0:如何限制对特定域的访问? - Google Oauth2.0 with Python: How do I limit access to a specific domain? 如何使用RESTEasy在Google App Engine中实现oAuth 2.0? - How do I implement oAuth 2.0 in Google App Engine with RESTEasy? Google Cloud OAuth 同意屏幕未反映(内部)应用程序 scope 的更改 - Google Cloud OAuth consent screen not reflecting changes to scope of (internal) app Python Google Drive API oauth2-保存用户的授权同意书 - Python Google Drive API oauth2 - Save authorization consent for user 如何使用 google.oauth2 python 库? - How do I use google.oauth2 python library? 如何从重定向的 url 中提取代码? (OAuth 2.0,烧瓶) - How do I extract code from redirected url? (OAuth 2.0, Flask) 谷歌 OAuth 2.0 使用 Python 用于 GCP BigQuery - Google OAuth 2.0 using Python for GCP BigQuery 试图在没有OAuth同意屏幕的情况下授权AWS Lambda进行Google Calendar API调用 - Attempting to Authorize AWS Lambda for Google Calendar API Call without OAuth Consent Screen 如何将本地Google App Engine Python数据存储区复制到本地Google App Engine Java数据存储区? - How do I copy local Google App Engine Python datastore to local Google App Engine Java datastore?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM