Google API OAuth 2.0 redirect_uri_mismatch 错误
Google APIs OAuth 2.0 redirect_uri_mismatch error
我正在尝试设置 Google Drive API 实例 Python 来下载文件。
我在我的 Google API 控制台上为特定项目设置了一个 OAuth 2.0 客户端 ID,并启用了 Google Drive API 客户端。但是,在本地主机上测试时,我不断收到 redirect_uri_mismatch 错误。我在某处读到将 http://localhost:8080 作为重定向 URI 进行测试,但是,redirect_uri_mismatch 错误一直在本地主机上的随机端口上抛出错误。我不确定如何为 localhost 设置正确的端口,所以这个错误不会一直被抛出。它目前表示实例尝试使用的重定向 URI 是 http://localhost:49334/。如果我将该 URI 添加到我的 credentials.json 文件中,那么它只会在不同的端口上抛出另一个不匹配错误。我该如何解决这个问题?我正在使用此文档中的代码:https://developers.google.com/drive/api/v3/quickstart/python and https://developers.google.com/drive/api/v3/manage-downloads.
请修改如下
请在 Google Cloud Platform 的“Google APIs Console's credentials section”设置重定向 uri,如下所示。修改后请保存。并请确认重定向url是否被修改
来自
http://localhost:8080
到
http://localhost:8080/
请按如下方式修改您的脚本。从您的回复中,我了解到您正在使用 the script of Quickstart for python.
来自
creds = flow.run_local_server(port=0)
到
creds = flow.run_local_server(port=8080)
运行脚本并授权。
我正在尝试设置 Google Drive API 实例 Python 来下载文件。 我在我的 Google API 控制台上为特定项目设置了一个 OAuth 2.0 客户端 ID,并启用了 Google Drive API 客户端。但是,在本地主机上测试时,我不断收到 redirect_uri_mismatch 错误。我在某处读到将 http://localhost:8080 作为重定向 URI 进行测试,但是,redirect_uri_mismatch 错误一直在本地主机上的随机端口上抛出错误。我不确定如何为 localhost 设置正确的端口,所以这个错误不会一直被抛出。它目前表示实例尝试使用的重定向 URI 是 http://localhost:49334/。如果我将该 URI 添加到我的 credentials.json 文件中,那么它只会在不同的端口上抛出另一个不匹配错误。我该如何解决这个问题?我正在使用此文档中的代码:https://developers.google.com/drive/api/v3/quickstart/python and https://developers.google.com/drive/api/v3/manage-downloads.
请修改如下
请在 Google Cloud Platform 的“Google APIs Console's credentials section”设置重定向 uri,如下所示。修改后请保存。并请确认重定向url是否被修改
来自
http://localhost:8080
到
http://localhost:8080/
请按如下方式修改您的脚本。从您的回复中,我了解到您正在使用 the script of Quickstart for python.
来自
creds = flow.run_local_server(port=0)
到
creds = flow.run_local_server(port=8080)
运行脚本并授权。