4

I am trying to connect to google drive and for that I am using python pydrive library. I have followed the documentation and written a snippet for connecting with google drive. But I get an error Error: redirect_uri_mismatch

The redirect URI in the request, http://localhost:8080/, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs

Here is the code of pydrive that I have executed (I have installed the pydrive library as well)

from pydrive.auth import GoogleAuth

gauth = GoogleAuth()
gauth.LocalWebserverAuth()

I am posting an image of my console.developer account, you can see I have written the address correctly as specified by the pydrive documentation. I have also added outcallback in the url but I am still getting the same error. Any help will be appreciated. Thanks Console.developers account

Added outhcallback

This is my client_secrets.json file content:

{"web":{,"project_id":"my-project-1532814702018","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","redirect_uris":["http://localhost:8080/oauth2callback"],"javascript_origins":["http://localhost","http://localhost:8080"]}}

(I have removed client id and client secret here)

4 Answers 4

13

I know its a bit late now, but it may help someone who encounters this issue. For me it was really silly. In "Authorized redirect URIs" field it must be "http://localhost:8080/" with a slash at end. In "Authorized JavaScript origins" it must be "http://localhost:8080" without a slash.

2

Edit Your URL and replace http://localhost:8080/ by http://localhost:8080

it works for me

0

You're almost there. Just add '/oauth2callback' as indicated in the greyed texts.

So, under 'Authorized redirect URIs' :

http://localhost:8080/oauth2callback
9
  • 1
    I have changed the url as you said but I am still getting the same error :( I have updated my question and added another image.
    – Shahab Ali
    Jul 30, 2018 at 13:46
  • download the new credentials.json. You might still be using the old credentials.json file Jul 30, 2018 at 14:35
  • no the file I am using is updated one, you can see the links in redirect_uris (I have updated the question)
    – Shahab Ali
    Jul 30, 2018 at 15:04
  • can you leave the pydrive library and use this quickstart for the meantime : developers.google.com/drive/api/v3/quickstart/python Jul 30, 2018 at 15:14
  • okay I can try on that but pydrive had built in functions that would have been really helpful :(
    – Shahab Ali
    Jul 30, 2018 at 15:28
0

It seems that google api has changed their policies on authorized domains, i heard there's remote domain that redirect to localhost? or you can change your hosts file... it doesnt make sense, because google supports api usage on native apps, why would they need a domain name?

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.