访问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);
请支持。
谢谢你, 叶夫
答案 0 :(得分:1)
从错误中看,开发人员控制台上的API项目似乎未正确配置(可以将Admin SDK设置为' OFF')。查看“设置您的API”下的here。了解更多信息。
当您说下面的代码完美无缺时,它是否正在使用另一个API项目?