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

时间:2018-07-27 12:29:45

标签: go google-apis-explorer google-directory-api

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

问题是,运行代码后,未添加Gsuite中的帐户。

相关代码(建立了具有admin身份验证的GSuite连接,该地图包含了所有用户条目。如果您仍然需要更多代码,我可以为您提供-只是想保持简单):

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"`
}

1 个答案:

答案 0 :(得分:0)

对于绊脚石的人。
代码段中的所有内容都是正确的。通过编写方法的方式,我希望adminService.Users.Update()实际上会更新用户。而是返回一个UserUpdatesCall
您需要通过调用.Do()
执行该更新 通过API:

  

执行“ directory.users.update”调用。

因此解决方案是更改adminService.Users.Update(u.Id, u)
进入adminService.Users.Update(u.Id, u).Do()