Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

golang gmail api quickstart results in localhost refused to connect ERR_CONNECTION_REFUSED

I’m following the steps in go quickstart gmail api.

On the func getTokenFromWeb method, pasting either the long url
https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=abcdefg.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.readonly&state=state-token

or
http://localhost:8000

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

results in

This site can't be reached. localhost refused to connect. ERR_CONNECTION_REFUSED

site can't be reached image

Following the same quickstart but for python works flawlessly.

If I get the token via python and use it in golang quickstart, it also works. So the issue is just on the token from web retrieval.

Thank you kindly in advance.

>Solution :

The issue you are having is related to the removal of oob. When that sample was originally created oob still worked. So it would display a nice web page for you where you could copy the authorization code.

That no longer works so we are forced to use http://127.0.0.1 or localhost. As your machine apparently does not have a web server running its displaying to you a 404 error.

However if you look in the URL bar you will find the authorization code you need in order to authorize your application.

The solution is to simply copy the code from the url bar. If you want to fix the 404 your going to have to figure out how to start a web server in order to host the http://127.0.0.1 from.

The python sample does this by running a local server

creds = flow.run_local_server(port=0)

Php can do it using something like this

php -S localhost:8000 -t examples/

Im not sure how that can be done with Go though.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading