代码之家  ›  专栏  ›  技术社区  ›  InDaPond

google directory api根据google api(在go中)向用户添加自定义模式/更新该模式

  •  0
  • InDaPond  · 技术社区  · 7 年前

    我正在尝试将自定义架构上载到GSuite中公司的所有用户。这个自定义模式包含了他们的GitHub用户名,我用GitHub API提取了这些用户名。

    问题是,运行代码后,GSuite中的帐户没有添加。

    相关代码(通过管理员身份验证建立到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 回复  |  直到 7 年前
        1
  •  0
  •   InDaPond    7 年前

    对于任何一个在这上面绊倒的人。
    代码段中的所有内容都是正确的。在编写方法的过程中,我希望 adminService.Users.Update() 实际更新用户。相反,它返回 UserUpdatesCall
    您需要通过调用 .Do()
    从API:

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

    所以解决办法是改变 adminService.Users.Update(u.Id, u)
    进入之内 adminService.Users.Update(u.Id, u).Do()