我正在尝试让我的谷歌身份验证在请求 Gmail 和日历数据的 Django 应用程序上运行。我已经在 Google 开发者控制台中设置了 oAuth API 并将其与我的项目链接,并且我已经三次检查我的重定向 URI 是否与代码中的完全匹配(HTTP 与 HTTPS 没有错误,斜杠也没有任何不一致) )。我确保我的密钥、密钥、ClientID 和 Client Secret 在 Django 应用程序的管理页面中均已配置且相同。我已经遵循了许多 youtube 教程并搜索了有关堆栈溢出的其他问题,但身份验证仍然无法正常工作。我收到错误 400:redirect_uri_mismatch。尽管我已经检查了很多次以确认它们是相同的。
从所有教程中,我了解到此错误有两个主要根源:
这两个错误都有自己的个性化消息,说明不匹配的类型。
然而,我的却是这样说的:您无法登录此应用程序,因为它不符合 Google 的 OAuth 2.0 政策。\n\n如果您是应用开发者,请在 Google Cloud Console 中注册重定向 URI。
这是错误的照片 [![Google 身份验证错误消息][1]][1]
from django.shortcuts import render, redirect
from django.http import HttpRequest
from google_auth_oauthlib.flow import Flow
from google.auth.transport.requests import Request
from googleapiclient.discovery import build
from .models import CredentialsModel
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
import os
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = …Run Code Online (Sandbox Code Playgroud) python django google-authenticator google-oauth google-api-python-client