第一次在这里使用OAuth,我被困住了。我正在构建一个web应用程序,需要对YouTube数据API进行授权调用。我正在测试本地计算机上的OAuth流。
当我试图在Python中运行Google时,我无法接收Error 400: redirect_uri_mismatch
。当我访问flow.run_console()
生成的链接时,会发生错误
这是我的代码:
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
client_secrets_file="./client_secret.json"
scopes = ["https://www.googleapis.com/auth/youtube.readonly"]
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
client_secrets_file, scopes)
flow.redirect_uri = "http://127.0.0.1:8080" # Authorized in my client ID
credentials = flow.run_console()
此代码返回消息:
Please visit this URL to authorize this application: ***google oauth url ***
Enter the authorization code:
访问链接会导致以下错误:
我尝试将OAuth客户端ID中的授权重定向URI设置为http://127.0.0.1:8080
,因为我是从本地机器进行测试的。我还在Python中将flow.redirect_uri
设置为http://127.0.0.1:8080
。使用http://127.0.0.1:8080
是我目前唯一的选择,因为前端还没有设置。
我希望代码能够授权我的请求,因为授权的URI与redirect_uri
匹配。但我仍然收到错误。
如果这有什么意义的话,我从谷歌的OAuth游乐场运行流量没有任何问题。
任何帮助都是非常感谢的,谢谢。
发布于 2022-11-04 16:20:58
将redirect_uri更改为http://127.0.0.1/
或http://localhost/
。我以前也面临过类似的问题,谷歌驱动器API,并删除端口号为我工作。
发布于 2022-11-30 11:11:12
图书馆好像有个bug。我知道这不太好,但在这种情况下,黑客是
flow._OOB_REDIRECT_URI = = "http://127.0.0.1:8080"
https://stackoverflow.com/questions/74320021
复制相似问题