簡體   English   中英

盡管 Google 帳戶是所有者,但來自 Google 身份驗證 web api 的“錯誤 403:access_denied”

[英]“Error 403: access_denied” from Google authentication web api despite google account being owner

我在這里使用谷歌提供的默認代碼,我不太明白為什么它不起作用。 代碼輸出提示Please visit this URL to authorize this application: [google login URL] 嘗試使用在 google 開發者控制台下指定為腳本所有者的帳戶登錄時,我收到Error 403: access_denied錯誤消息The developer hasn't given you access to this app. It's currently being tested and it hasn't been verified by Google. If you think you should have access, contact the developer [the email I just tried to log in with]. The developer hasn't given you access to this app. It's currently being tested and it hasn't been verified by Google. If you think you should have access, contact the developer [the email I just tried to log in with].

from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly']

# The ID and range of a sample spreadsheet.
SAMPLE_SPREADSHEET_ID = '1vrZpCGW58qCCEfVXoJYlwlulraIlfWI2SmFXa1iPtuU'
SAMPLE_RANGE_NAME = 'Class Data!A2:E'

def main():
    """Shows basic usage of the Sheets API.
    Prints values from a sample spreadsheet.
    """
    creds = None
    # The file token.pickle stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)
    # If there are no (valid) credentials available, let the user log in.
    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(
                'Google_API_Key.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    service = build('sheets', 'v4', credentials=creds)

    # Call the Sheets API
    sheet = service.spreadsheets()
    result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID,
                                range=SAMPLE_RANGE_NAME).execute()
    values = result.get('values', [])

    if not values:
        print('No data found.')
    else:
        print('Name, Major:')
        for row in values:
            # Print columns A and E, which correspond to indices 0 and 4.
            print('%s, %s' % (row[0], row[4]))

def PrintToSheets():
    main()

編輯:我知道已經有答案了,但是對於那些(比如我自己)需要更清楚的人來說,這是一個步驟格式

為我解決這個問題很簡單:

  1. Go 到https://console.developers.google.com/
  2. 在“Google APIs”字樣旁邊的左上角單擊右側的項目下拉菜單
  3. 確保選擇了正確的項目
  4. 單擊屏幕左側的“OAuth 同意屏幕”(“憑據”下方)
  5. 如果您尚未創建同意屏幕,請先創建
  6. 在“測試用戶”下有一個名為“+ 添加用戶”的按鈕
  7. 輸入您將要測試的帳戶的 email,按 Enter,然后單擊保存。
  8. 它現在應該可以工作了!

好像他們最近更新了這個,因為去年我不必這樣做。

您收到的錯誤消息與您的應用程序尚未通過驗證有關。

正如該鏈接中提到的,所有使用敏感范圍訪問谷歌 API 的應用程序都需要通過谷歌驗證過程 go。 正常情況下,在您的應用程序被鎖定之前,您有 100 個用戶訪問您的應用程序的寬限期,並且在您驗證您的應用程序之前,您將無法授權更多用戶,聽起來您可能已經達到了這一點。

您唯一的選擇是通過驗證過程使用 go,或者在 Google 開發人員控制台上創建一個全新的項目並使用該客戶端 ID,因為您正在使用的客戶端 ID 目前已鎖定以供其他用戶使用。

更新變更

已在 Google Developer 控制台上實施了一項更改。 您現在必須授權用戶/測試人員訪問您的應用程序,然后才能完成驗證過程。 如果您 go 到您的項目的 Google 開發人員控制台,在同意屏幕下,您將找到以下部分

在此處輸入圖像描述

您可以在此處添加測試用戶,但不能刪除它們,您只能添加 100 個,因此請明智地使用它。

暫無
暫無

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

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