2

I'm using the https://developers.google.com/drive/api/v3/quickstart/python to access the Google Drive Api but Google keeps throwing redirect_uri_mismatch errors.

I add the localhost:number from the error to the Authorised redirect URIs in the client ID for the Web Application, but whenever I run the quickstart.py, the local host number changes.

I see there are loads of questions regarding this matter on StackOverflow and I've already spent hours looking to fix mine but I haven't found an answer that seems to solve it for me.

Any ideas?


Tried answers from, amongst others,


Currently

enter image description here

LucSpan
  • 1,831
  • 6
  • 31
  • 66
  • what is your redirect_uri? – Adam Strauss Sep 18 '20 at 13:39
  • I've removed all URIs I tried and kept only `http://localhost:8080/` – LucSpan Sep 18 '20 at 13:55
  • By the way how you add code snippet in comment :p – Adam Strauss Sep 18 '20 at 13:59
  • See screenshot added of current setting. You add code in comment the same way as in the question: place the code between 2 `. – LucSpan Sep 18 '20 at 14:00
  • `http://localhost:8080/` and `http://localhost:8080` are different please make sure – Adam Strauss Sep 18 '20 at 14:01
  • You mean I should put 8000 in stead of 8080? I just added them to the URIs but issue persists. – LucSpan Sep 18 '20 at 14:03
  • No I'm saying please double check if you're using same redirect_uri on both side...because sometimes we use `http://localhost:8080/` and place redirect_uri `http://localhost:8080` both are different – Adam Strauss Sep 18 '20 at 14:11
  • Yes, I'm aware. Sadly it doesn't matter, issue still persists. – LucSpan Sep 18 '20 at 14:26
  • 2
    Although I'm not sure whether this is the direct solution, if you are using [the script of Quickstart](https://developers.google.com/drive/api/v3/quickstart/python), please modify `creds = flow.run_local_server(port=0)` to `creds = flow.run_local_server(port=8080)`, and test it again. When `port=0` is used, it seems that the random port is used. – Tanaike Sep 19 '20 at 00:33
  • Now I found your answer. I'm glad your issue was resolved. Also, now I found [this thread](https://stackoverflow.com/q/62982754/7108653). So this was the answer for your question. I apologize I couldn't find that before. – Tanaike Sep 19 '20 at 11:09
  • 2
    Does this answer your question? [Google APIs OAuth 2.0 redirect\_uri\_mismatch error](https://stackoverflow.com/questions/62982754/google-apis-oauth-2-0-redirect-uri-mismatch-error) – Tanaike Sep 19 '20 at 11:10
  • Yes it does. Thank you! – LucSpan Sep 20 '20 at 10:33

2 Answers2

4

Tanaike's comment and answer here worked: Google APIs OAuth 2.0 redirect_uri_mismatch error

So in quickstart.py, make the following change,

creds = flow.run_local_server(port=0) 

to,

creds = flow.run_local_server(port=8080) 

when http://localhost:8080/ is on the URIs list.

LucSpan
  • 1,831
  • 6
  • 31
  • 66
0

Like LucSpan mentioned in the comments of the answer. the redirect URI needs to be "http://localhost:8080/" and not "http://localhost:8080" the missing "/" at the end matters

kritin
  • 1
  • 1