0
votes

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
In order to correctly understand about your current situation, can you provide your current script for replicating your issue? By the way, from your question, I thought that you might create the credential files including the client secret as the web application. In that case, you have set http://localhost:8080 to the redirect uri? - Tanaike
The current script is on this documentation I posted: developers.google.com/drive/api/v3/quickstart/python. I don't do anything different to the code, exact same code. Also yes in the credentials.json file that you download from Google APIs Console's credentials section, I set the redirect uri to http://localhost:8080. - nenur
Thank you for replying. From your replying, I proposed the modification points as an answer. Could you please confirm it? If that was not the solution of your issue, I apologize. - Tanaike

1 Answers

1
votes

Please modify as follows.

  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/
      
  2. 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)
      
  3. Run the script and authorize.