我在访问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);
请支持。
谢谢你,Evgeny
从错误中,看起来您在开发人员控制台上的API项目没有正确配置(可以将Admin SDK设置为'OFF')。查看这里的"设置您的API"获取更多信息。
当你说下面的代码工作完美,它是使用另一个API项目?