第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用 Oauth2 登錄 Google Colab

使用 Oauth2 登錄 Google Colab

侃侃爾雅 2022-01-18 17:37:37
我正在嘗試使用 Oauth 2.0 登錄 Google Colab 筆記本,但啟動(dòng)的 Google 登錄網(wǎng)頁(yè)以不存在的 web 結(jié)束(http://localhost:8090/?code=4/NAFDWUxkOxp3FIlB9I_vxFTFm-zjAx0XJpEspQ9dGozG-0L3ccthFD12FAhq_B5hLWTxDFuUg_SjC011V9jiLDw&scope=https://www.googleapis.com/auth/admin.directory.group.member%20https://www.googleapis.com/auth/admin.directory.group%20https://www.googleapis.com/auth/apps.groups.settings)。也許該錯(cuò)誤與任何回調(diào) url 有關(guān),但我不知道如何解決。這是我用于登錄的代碼。import osos.environ['USE_NATIVE_IPYTHON_SYSTEM_COMMANDS'] = '1'import httplib2from oauth2client.client import flow_from_clientsecretsfrom oauth2client.file import Storagefrom oauth2client.tools import run_flowfrom oauth2client import toolsfrom google.colab import drive; drive.mount('/content/drive')PATH_BASE = '/content/drive/My Drive/.../'CLIENT_SECRET = PATH_BASE + 'client_secret_event.json'SCOPES = [ "https://www.googleapis.com/auth/admin.directory.group", "https://www.googleapis.com/auth/admin.directory.group.member", "https://www.googleapis.com/auth/apps.groups.settings"]STORAGE = Storage(PATH_BASE + 'credentials.storage')flags = tools.argparser.parse_args([])# Start the OAuth flow to retrieve credentialsdef authorize_credentials():    # Fetch credentials from storage    credentials = STORAGE.get()    # If the credentials doesn't exist in the storage location then run the flow    if credentials is None or credentials.invalid:        flow = flow_from_clientsecrets(CLIENT_SECRET, scope=SCOPES)        http = httplib2.Http()        credentials = run_flow(flow, STORAGE, flags, http=http)    return credentialscredentials = authorize_credentials()關(guān)于為什么會(huì)發(fā)生這種情況的任何想法?
查看完整描述

3 回答

?
catspeake

TA貢獻(xiàn)1111條經(jīng)驗(yàn) 獲得超0個(gè)贊

有一個(gè)如何使用InstalledAppFlow將 Google Docs 與 python 一起使用的示例:

from google_auth_oauthlib.flow import InstalledAppFlow


查看完整回答
反對(duì) 回復(fù) 2022-01-18
?
滄海一幻覺(jué)

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超5個(gè)贊

您將希望使用已安裝的應(yīng)用程序流而不是 Web 應(yīng)用程序流。

原因是 Colab 后端沒(méi)有直接暴露給 Internet,因此無(wú)法處理基于 Web 的 OAuth 流常見(jiàn)的 URL 重定向。


查看完整回答
反對(duì) 回復(fù) 2022-01-18
?
慕斯王

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個(gè)贊

按照評(píng)論和本教程(您可以從中受益以在控制臺(tái)中創(chuàng)建應(yīng)用程序),我實(shí)現(xiàn)了以下代碼:


creds = None


# Check if previous log-in exists

if os.path.exists('/content/drive/MyDrive/Projects/xyz/token.pickle'):

  with open('/content/drive/MyDrive/Projects/xyz/token.pickle', 'rb') as token:

    creds = pickle.load(token)


# If not available or invalid, log in using the "console" InstalledAppFlow

if not creds or not creds.valid:

  if creds and creds.expired and creds.refresh_token:

    creds.refresh(Request())

  else:

    flow = InstalledAppFlow.from_client_secrets_file('/content/drive/MyDrive/Projects/xyz/credentials.json', SCOPES)

    creds = flow.run_console()


  # Save the access token in token.pickle file for the next run

  with open('/content/drive/MyDrive/Projects/xyz/token.pickle', 'wb') as token:

    pickle.dump(creds, token)


# Connect to the Gmail API

service = build('gmail', 'v1', credentials=creds)


查看完整回答
反對(duì) 回復(fù) 2022-01-18
  • 3 回答
  • 0 關(guān)注
  • 296 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)