简体   繁体   English

Go gmail api 快速启动导致本地主机拒绝连接 ERR_CONNECTION_REFUSED

[英]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.

相关问题 尝试连接到本地主机时出现“连接:连接被拒绝” - "connect: connection refused" while attempting to connect to localhost 使用Go和Localhost拒绝连接来制作简单的FileServer - Making a Simple FileServer with Go and Localhost Refused to Connect Docker 获取 http://localhost:8091/api/order: 拨打 tcp 127.0.0.1:8091: 连接连接被拒绝 - Docker Get http://localhost:8091/api/order: dial tcp 127.0.0.1:8091: connect: connection refused 在Heroku上,Go + Postgres拒绝连接 - Connection refused with Go + Postgres on Heroku 无法使用 go 和 docker 连接到 mysql 服务器 - 拨打 tcp 127.0.0.1:3306:连接:连接被拒绝 - Unable to connect to mysql server with go and docker - dial tcp 127.0.0.1:3306: connect: connection refused Go Mysql 连接被拒绝,因为连接爆裂 - Go Mysql connection refused due to a burst of connections Go 程序在连接被拒绝后退出 - Go program exits after a connection refused go&mysql&docker 拒绝连接 - connection refused with go&mysql&docker 拨打 tcp 127.0.0.1:8080:连接:连接被拒绝。 go docker 应用程序 - dial tcp 127.0.0.1:8080: connect: connection refused. go docker app Go中的RabbitMQ:机械工人无法使用getsockopt消息连接到0.0.0.0:5672:连接被拒绝 - RabbitMQ in Go: machinery worker cannot to connect to 0.0.0.0:5672 with message getsockopt: connection refused
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM