[英]Go gmail api quickstart results in localhost refused to connect ERR_CONNECTION_REFUSED
I'm following the steps in go quickstart gmail api .我按照go 快速入门 gmail api中的步骤操作。
On the function getTokenFromWeb
, 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
在 function
getTokenFromWeb
上,粘贴长 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
results in结果是
This site can't be reached.
无法访问此站点。 localhost refused to connect.
本地主机拒绝连接。 ERR_CONNECTION_REFUSED
ERR_CONNECTION_REFUSED
Following the same quickstart but for python works flawlessly.按照相同的快速入门,但python可以完美运行。
If I get the token via python and use it in Go quickstart, it also works.如果我通过 python 获得令牌并在 Go 快速入门中使用它,它也可以工作。 So the issue is just on the token from web retrieval.
所以问题就出在从 web 检索到的令牌上。
The issue you are having is related to the removal of oob .您遇到的问题与oob的删除有关。 When that sample was originally created oob still worked.
当最初创建该示例时,oob 仍然有效。 So it would display a nice web page for you where you could copy the authorization code.
因此它会为您显示一个漂亮的 web 页面,您可以在其中复制授权代码。
That no longer works so we are forced to use http://127.0.0.1 or localhost.这不再有效,因此我们被迫使用http://127.0.0.1或本地主机。 As your machine apparently does not have a web server running its displaying to you a 404 error.
由于您的机器显然没有运行 web 服务器,因此向您显示 404 错误。
However if you look in the URL bar you will find the authorization code you need in order to authorize your application.但是,如果您查看 URL 栏,您会找到授权您的应用程序所需的授权代码。
The solution is to simply copy the code from the url bar.解决办法就是简单的复制url吧的代码。 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.
如果你想修复 404,你将不得不弄清楚如何启动 web 服务器,以便从中托管http://127.0.0.1 。
The python sample does this by running a local server python 示例通过运行本地服务器来执行此操作
creds = flow.run_local_server(port=0)
Php can do it using something like this Php 可以用这样的东西来做
php -S localhost:8000 -t examples/
Im not sure how that can be done with Go though.我不确定如何使用 Go 来完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.