gpt4 book ai didi

Google Directory API 添加自定义架构/根据 google API 将其更新给用户(在进行中)

转载 作者:数据小太阳 更新时间:2023-10-29 03:22:23 26 4
gpt4 key购买 nike

我正在尝试将 CustomSchema 上传到 GSuite 中一家公司的所有用户。此自定义架构包含他们的 Github 用户名,我使用 github API 将其提取。

问题是,运行代码后,并没有添加Gsuite中的账号。

相关代码(已建立使用管理员身份验证的 GSuite 连接, map 包含所有用户条目。如果您还需要更多代码,我可以为您提供 - 只是尽量保持简单):

for _, u := range allUsers.Users {

if u.CustomSchemas != nil {
log.Printf("%v", string(u.CustomSchemas["User_Names"]))
}else{
u.CustomSchemas = map[string]googleapi.RawMessage{}
}
nameFromGsuite := u.Name.FullName
if githubLogin, ok := gitHubAccs[nameFromGsuite]; ok {

userSchemaForGithub := GithubAcc{GitHub: githubLogin}
jsonRaw, err := json.Marshal(userSchemaForGithub)
if err != nil {
log.Fatalf("Something went wrong logging: %v", err)
}

u.CustomSchemas["User_Names"] = jsonRaw
adminService.Users.Update(u.Id, u)

} else {
log.Printf("User not found for %v\n", nameFromGsuite)
}
}

这是 json 编码的结构:

 type GithubAcc struct {
GitHub string `json:"GitHub"`
}

最佳答案

致任何遇到此问题的人。
代码片段中的所有内容都是正确的。顺便说一句,我预计 adminService.Users.Update() 确实会更新用户。相反,它返回一个 UserUpdatesCall
您需要通过调用 .Do()
来执行该更新来自 API:

Do executes the "directory.users.update" call.

所以解决方案是改变adminService.Users.Update(u.Id, u)
进入 adminService.Users.Update(u.Id, u).Do()

关于Google Directory API 添加自定义架构/根据 google API 将其更新给用户(在进行中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51557984/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com