簡體   English   中英

如何在本地Python代碼中打開Goog​​le OAuth 2.0許可屏幕?

[英]How do I open a Google OAuth 2.0 consent screen in a local Python code?

如何使用本地Python代碼中的同意屏幕獲取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筆記本或代碼中打開我的同意屏幕? 是否有上述流程將啟動同意屏幕,允許我在那里進行身份驗證,收集(臨時)令牌,並粘貼它以響應提示的提示?

google.colab庫在Colab之外是不可用的。

gspread文檔描述了如何通常對庫進行身份驗證: https//github.com/burnash/gspread#basic-usage

重現相關代碼段:

  1. Google Developers Console獲取OAuth2憑據
  2. 開始使用gspread:

     import gspread gc = gspread.authorize(credentials) 

大部分工作都是通過鏈接中描述的雲項目創建過程完成的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM