ste*_*nos 1 java google-apps google-apps-marketplace
我正在创建一个应该能够读取域的所有用户的Marketplace应用程序.我请求访问这些范围:
https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/userinfo.profile
https://www.googleapis.com/auth/admin.directory.user.readonly
Run Code Online (Sandbox Code Playgroud)
然后当访问"通用导航扩展"时,会发生这种情况:
Credential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(SERVICE_MAIL)
.setServiceAccountScopes(Arrays.asList(DirectoryScopes.ADMIN_DIRECTORY_USER_READONLY))
.setServiceAccountPrivateKey(privateKey)
.build();
Directory oauth2 = new Directory.Builder(httpTransport, jsonFactory, null)
.setHttpRequestInitializer(credential)
.build();
Directory.Users.List list = oauth2.users().list();
list.setDomain(queryParams.getString("domain"));
Users users = list.execute();
Run Code Online (Sandbox Code Playgroud)
当我运行它时,它返回此错误:
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Not Authorized to access this resource/api",
"reason" : "forbidden"
} ],
"message" : "Not Authorized to access this resource/api"
}
Run Code Online (Sandbox Code Playgroud)
但是,当我添加:
Credential credential = new GoogleCredential.Builder()
.setServiceAccountUser("<admin-account>@<domain>")
...
Run Code Online (Sandbox Code Playgroud)
有用!
但我怎么知道管理员的电子邮件地址?我可以在没有电子邮件地址的情况下工作吗?
| 归档时间: |
|
| 查看次数: |
520 次 |
| 最近记录: |