通过目录Google API提供用户信息时发出问题

时间:2014-05-23 15:38:07

标签: google-api google-apps

访问Directory API以获取有关用户的数据时遇到问题:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
  "code" : 403,
  "errors" : [ {
    "domain" : "usageLimits",
    "message" : "Access Not Configured. Please use Google Developers Console to activate the API for your project.",
    "reason" : "accessNotConfigured"
  } ],
  "message" : "Access Not Configured. Please use Google Developers Console to activate the API for your project."
}.

我用来访问它的代码:

    Directory service = (Directory) GoogleClientHelper.getClientOAuth20(Directory.Builder.class, email, null, null);
    Directory.Users.Get request = service.users().get(email);
    User user = request.execute();

但是,以下代码完美无缺:

        Directory service = (Directory) GoogleClientHelper.getClientOAuth20(Directory.Builder.class, email, null, null);
        Directory.Users.List request = service.users().list().setCustomer(adminAccount);

        do {
            try {
                Users currentPage = request.execute();
                allUsers.addAll(currentPage.getUsers());
                request.setPageToken(currentPage.getNextPageToken());
            } catch (IOException e) {
                System.out.println("An error occurred: " + e);
                request.setPageToken(null);
            }
        } while (request.getPageToken() != null && request.getPageToken().length() > 0);

请支持。

谢谢你, 叶夫

1 个答案:

答案 0 :(得分:1)

从错误中看,开发人员控制台上的API项目似乎未正确配置(可以将Admin SDK设置为' OFF')。查看“设置您的API”下的here。了解更多信息。

当您说下面的代码完美无缺时,它是否正在使用另一个API项目?