概要:
在Go中使用Gmail API的示例包括用于从文件系统内的已知JSON文件读取凭据的代码。我想利用应用程序默认凭据(ADC),因为我们正在部署到可以访问Gmail API的k8s。
码:
请从下面的full demo中找到节选:
//error handling omited for brevity
b, _ := ioutil.ReadFile("credentials.json")
config, _ := google.ConfigFromJSON(b, gmail.GmailReadonlyScope) //is it possible to replace this?
client := getClient(config)
srv, _ := gmail.New(client)
如何在摘录中替换第2行以获得相同的配置,但不使用显式的JSON凭证文件?
最佳答案
您可以使用gcloud auth application-default print-access-token打印访问 token 。使用它向API发出请求,而不是从文件中读取。 –天线
关于go - 使用默认凭据对Gmail API进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63720630/