go - 使用默认凭据对Gmail API进行身份验证

标签 go google-cloud-platform gmail-api credentials

概要:
在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/

相关文章:

python - 将电子邮件从一个 Gmail 邮箱导入到另一个邮箱

go - Kafka 生产者不通过分区分发消息

sql-server - 远程连接到在 Google Cloud 虚拟机上运行的 SQL Server 的秘诀是什么?

google-cloud-platform - 删除桶后实际对象计数不正确

java - Gmail API 删除不起作用

node.js - gmail API 快速入门在 google.gmail ('v1' 处失败)

google-app-engine - GO源代码是否已上传到谷歌应用引擎?

go - Golang中int8、int16、int32分别分配了多少内存?

go - 除非 EOF,否则只读取 n 个字节?

python - 使用 Python SDK 在 GCP 中获取区域集群