简体   繁体   English

Go中无人值守的Google API授权

[英]Unattended authorisation to Google API in Go

I've been trying to find a way to interact with Google's API (specifically, the Compute Engine API) without having the user authorise via a consent screen each time I need to reauthorise with Google. 我一直在努力寻找一种与Google的API(特别是Compute Engine API)进行互动的方法,而无需在每次我需要重新授权Google时通过同意屏幕进行用户授权。

The requests will be made when no user is present, so not having to authorise via a consent screen is an absolute must. 当没有用户在场时,将提出请求,因此不必通过同意屏幕进行授权是绝对必要的。

I'm using Go and the Go API Client Library. 我正在使用Go和Go API客户端库。

Can anybody explain a method to achieve what I need to? 任何人都可以解释一种方法来实现我需要的东西吗?

You should take a look at service accounts. 你应该看看服务帐户。 They utilize the public/private key pair to authorize calls to Google API. 他们利用公钥/私钥对授权调用Google API。

Google Developers has one very nice document explaining how service accounts work: Google Developers有一个很好的文档,解释了服务帐户的工作方式:

https://developers.google.com/accounts/docs/OAuth2ServiceAccount https://developers.google.com/accounts/docs/OAuth2ServiceAccount

Here's how generate a service account: 以下是生成服务帐户的方法:

https://developers.google.com/console/help/new/#serviceaccounts https://developers.google.com/console/help/new/#serviceaccounts

You will also find the code samples in the first doc, but unfortunately not in Go. 您还可以在第一个文档中找到代码示例,但遗憾的是不在Go中。 However, there are some comments that I found here: 但是,我在这里发现了一些评论:

https://code.google.com/p/google-api-go-client/wiki/GettingStarted https://code.google.com/p/google-api-go-client/wiki/GettingStarted

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM