Error: redirect_uri_mismatch in Google drive

Error: redirect_uri_mismatch in Google drive

我正在尝试访问我的驱动器,并且我已经根据此处的答案尝试了不同的选项...什么应该是正确的 URI,这样它才不会不匹配?

授权Javascript是 http://localhost:8080 重定向 URI 是 http://localhost:8080/

这是凭证文件

{"web":{"client_id":"1038794891433-f5vuivrc93fvqj9o65elka0shksbee5a.apps.googleusercontent.com","project_id":"bitcoin-961cf","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"","redirect_uris":["http://localhost:8080/"],"javascript_origins":["http://localhost:8080"]}}

错误:

The redirect URI in the request, http://localhost:62605/, does not match the ones authorized for the OAuth client.

我使用的是标准文档脚本

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

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

def main():
    """Shows basic usage of the Drive v3 API.
    Prints the names and ids of the first 10 files the user has access to.
    """
    creds = None
    # The file token.json 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.json'):
        creds = Credentials.from_authorized_user_file('token.json', SCOPES)
    # 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(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('token.json', 'w') as token:
            token.write(creds.to_json())

    service = build('drive', 'v3', credentials=creds)

    # Call the Drive v3 API
    results = service.files().list(
        pageSize=10, fields="nextPageToken, files(id, name)").execute()
    items = results.get('files', [])

    if not items:
        print('No files found.')
    else:
        print('Files:')
        for item in items:
            print(u'{0} ({1})'.format(item['name'], item['id']))

if __name__ == '__main__':
    main()

在我的例子中,就是这一行

creds = flow.run_local_server(port=0)

需要改成

creds = flow.run_local_server(port=8080)

http://localhost:62605/ 在 google console

的重定向 URI 中添加这个

但您拥有 Web 客户端的凭据并且您正在关注桌面客户端的文档