Google API OAuth 2.0 redirect_uri_mismatch错误 [英] Google APIs OAuth 2.0 redirect_uri_mismatch error

查看:143
本文介绍了Google API OAuth 2.0 redirect_uri_mismatch错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Python设置Google Drive API实例以下载文件. 我在Google API控制台上为特定项目设置了OAuth 2.0客户端ID,并启用了Google Drive API客户端.但是,在localhost上进行测试时,我不断收到redirect_uri_mismatch错误.我读到某处将http://localhost:8080用作测试的重定向URI,但是,redirect_uri_mismatch错误不断将错误抛出在localhost的随机端口上.我不确定如何为本地主机设置正确的端口,因此不会不断抛出此错误.当前,它表示实例尝试使用的重定向URI为http://localhost:49334/.如果我将该URI添加到我的certificate.json文件中,那么它将在另一个端口上引发另一个不匹配错误.如何解决此问题?我正使用本文档中的代码: https://developers.google.com /drive/api/v3/quickstart/python https://developers.google.com/drive/api/v3/manage-downloads .

I am trying to set up a Google Drive API instance with Python to download files. I set up an OAuth 2.0 Client ID on my Google APIs Console for a specific project and have enabled the Google Drive API client. However, I keep getting a redirect_uri_mismatch error when testing on localhost. I read somewhere to include http://localhost:8080 as the redirect URI for testing, however, the redirect_uri_mismatch error keeps throwing the error on a random port on localhost. I am not sure how to set up a correct port for localhost so this error doesn't keep getting thrown. It currently says that the redirect URI the instance is trying to use is http://localhost:49334/. If I add that URI to my credentials.json file, then it just throws another mismatch error over a different port. How do I fix this issue? I am exactly using code from this documentation: https://developers.google.com/drive/api/v3/quickstart/python and https://developers.google.com/drive/api/v3/manage-downloads.

推荐答案

请进行如下修改.

  1. 请在"Google API控制台的凭据部分"中设置重定向uri如下所示.修改后,请保存.并请确认重定向网址是否已修改.

  1. Please set the redirect uri at "Google APIs Console's credentials section" of Google Cloud Platform as follows. When you modified it, please save it. And please confirm whether the redirect url was modified.

  • 来自

  • From

  http://localhost:8080

  • 收件人

  • To

      http://localhost:8080/
    

  • 请如下修改您的脚本.从您的回复中,我了解到您正在使用 Python快速入门脚本.

    Please modify your script as follows. From your replying, I understand that you are using the script of Quickstart for python.

    • 来自

    • From

      creds = flow.run_local_server(port=0)
    

  • 收件人

  • To

      creds = flow.run_local_server(port=8080)
    

  • 运行脚本并进行授权.

    这篇关于Google API OAuth 2.0 redirect_uri_mismatch错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆