【问题标题】:Error finding UserKey with Google Directory Admin API使用 Google Directory Admin API 查找 UserKey 时出错
【发布时间】:2015-03-05 12:46:21
【问题描述】:

我有一些代码来检索、删除和更新,以及创建谷歌用户。我可以使用以下方法毫无问题地创建用户:

public void createUser(String id, String firstName, String lastName, String email, String password){

    User user = new User();

    try{


        UserName name = new UserName();
        name.setFamilyName(lastName);
        name.setGivenName(firstName);
        user.setName(name);
        user.setPassword(password);
        user.setPrimaryEmail(email);
        user.setId(id);

        System.out.println(service.users().insert(user).execute());         
    }
    catch(Exception e){
        System.out.println("Error creating user: " + e);
    }

我还可以通过以下方式检索 userKey:

System.out.println("UserKey: " + service.users().get(id).getUserKey());

但是当我尝试使用 id 更新或删除用户时,我收到以下错误:

 com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
{
  "code" : 404,
  "errors" : [ {
  "domain" : "global",
  "message" : "Resource Not Found: userKey",
  "reason" : "notFound"
} ],
"message" : "Resource Not Found: userKey"
}

我的删除方法如下:

public void deleteUser(String id){
    try{
        System.out.println(service.users().delete(id).execute());
    }
    catch(Exception e){
        System.out.println("Error deleting user: " + e);
    }
}

如果我将删除或更新方法传递给电子邮件地址 (id@domain.edu),它会找到帐户并正常工作,但我需要能够仅传递我在插入方法中创建帐户时使用的 id .有什么想法吗?

【问题讨论】:

  • 当您提到“id”时,您指的是 Google 维护的用户的 Google ID(所有 Google 帐户唯一)还是您指的是用户电子邮件地址的本地部分(例如user@domain.com 中的用户)?
  • 它应该是电子邮件地址的本地部分。当我使用 id 调用 getUserKey 方法(我的代码大约一半)时,它返回 userKey 作为我在创建用户时设置的 id。

标签: java google-admin-sdk


【解决方案1】:

调用 Directory API 时,您必须始终指定用户的完整电子邮件地址或用户的 Google 唯一 ID。仅提供用户名的本地部分是不够的,因为这不允许 Google 确定用户与哪个 Google Apps 域相关联。

【讨论】:

  • 谢谢。在我使用它之前,我将只传递 id 并添加“@domain.edu”。
猜你喜欢
  • 1970-01-01
  • 2013-07-16
  • 2013-07-27
  • 2013-06-06
  • 1970-01-01
  • 1970-01-01
  • 2013-11-23
  • 1970-01-01
  • 2014-08-09
相关资源
最近更新 更多