我正在尝试使用Google Admin SDK的Java客户端,特别是Directory API.它基于GoogleCredentials的使用,就像Google Drive API一样.但是,与谷歌驱动器不同的是,我收到了400 - 目录中的错误请求错误.我按如下方式设置API:
Directory directory = new Directory.Builder(TRANSPORT, FACTORY, credential).build();
Directory.Users.List list = directory.users().list();
Users users = list.execute();
Run Code Online (Sandbox Code Playgroud)
最后一个execute()生成列在帖子底部的错误和堆栈跟踪.我正在使用以下范围来授权自己.我也可以使用Drive API.
https://www.googleapis.com/auth/userinfo.profile
https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/admin.directory.user
Run Code Online (Sandbox Code Playgroud)
访问Drive API就像魅力一样.我可以毫无问题地请求文件.但是,如果我对Directory API执行简单操作,则会收到下面列出的错误和堆栈跟踪.我应该提一下,Drive API和Directory API都指向我是管理员的相同Google Apps域.我还在Google API控制台中启用了这两个API.对于其他人,我无法弄清楚我做错了什么,我想知道是否有其他人看到类似的东西,或者有其他经验通过Java客户端访问这个API.
谢谢,
拉尔夫
[ERROR] com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 OK
[ERROR] {
[ERROR] "code" : 400,
[ERROR] "errors" : [ {
[ERROR] "domain" : "global",
[ERROR] "message" : "Bad Request",
[ERROR] "reason" : "badRequest"
[ERROR] } ],
[ERROR] "message" : "Bad Request"
[ERROR] }
[ERROR] at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
[ERROR] …Run Code Online (Sandbox Code Playgroud)