问题描述
我有一个使用 Google 服务帐户连接到 Google People API 的聊天机器人。机器人接收一个事件,其中包含消息发件人的 Google ID(即 1234567890987654321
)。我想使用服务帐户查找邮件发件人的姓名和电子邮件地址。
我相信 https://www.googleapis.com/auth/directory.readonly
scope should allow this,为服务帐户设置了域范围的委派。但是响应不包括请求的字段,只填充了 Etag 和 ResourceName。
我可以更改或配置哪些内容以在使用服务帐户的 People.Get 调用中包含任意目录用户的姓名和电子邮件?
package main
import (
"context"
"log"
"google.golang.org/apI/Option"
"google.golang.org/api/people/v1"
)
func main() {
// Service account's credentials
apiKeyFile := "credentials.json"
// Google ID of a person within your directory
resourceName := "people/1234567890987654321"
fields := "names,emailAddresses"
ctx := context.Background()
// directory.readonly scope is included by default
s,_ := people.NewService(ctx,option.WithCredentialsFile(apiKeyFile))
pCall := s.People.Get(resourceName)
pCall.PersonFields(fields)
person,_ := pCall.Do()
log.Print(person.Etag)
for _,address := range person.EmailAddresses {
log.Print(address.Value)
}
for _,name := range person.Names {
log.Print(name.displayName)
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)