gpt4 book ai didi

java - GoogleJsonResponseException : 404 Not Found during getting user list of enterprise

转载 作者:行者123 更新时间:2023-11-30 07:58:03 25 4
gpt4 key购买 nike

我正在使用 Google Play EMM API (lib google-api-services-androidenterprise-v1-rev8-1.20.0.jar) 编写简单的应用程序,该应用程序应生成用于自动安装设备策略 Controller (Android for Work) 的激活代码)在设备上。

HttpTransport sHttpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory sJsonFactory = JacksonFactory.getDefaultInstance();

GoogleCredential credentials = new GoogleCredential.Builder().setTransport(sHttpTransport).setJsonFactory(sJsonFactory)
.setServiceAccountId(MASTER_SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(AndroidEnterpriseScopes.all())
.setServiceAccountPrivateKeyFromP12File(new File(PRIVATE_KEY_P12_FILE_NAME))
.build();

AndroidEnterprise sAndroidEnterprise = new AndroidEnterprise(sHttpTransport, sJsonFactory, credentials);

String userId = sAndroidEnterprise.users().list(enterpriseId, userEmail).execute()
.getUser()
.get(0)
.getId();

String activationCode = sAndroidEnterprise.users().generateToken(enterpriseId, userId).execute().getToken();

问题是我在方法execute()中得到异常结果

String userId = sAndroidEnterprise.users().list(enterpriseId, userEmail).execute()

com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
{
"code" : 404,
"errors" : [ {
"domain" : "global",
"location" : "enterpriseId",
"locationType" : "parameter",
"message" : "No enterprise was found for the given id.",
"reason" : "notFound"
} ],
"message" : "No enterprise was found for the given id."
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1056)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)

最有趣的是,如果我将不存在的电子邮件作为参数 userEmail,方法execute() 也不异常(exception),当然方法getUser() 返回null。

如何修复此代码以成功获取用户 ID?对我来说,这看起来像是库或服务器的问题,但我希望我只是做错了什么。

请注意:我已成功注册客户并按照 https://developers.google.com/play/enterprise/samples 做好准备工作

最佳答案

您似乎正在使用 MSA 帐户进行身份验证来调用 users() 方法。尝试使用 ESA 帐户进行身份验证,即您在请求中提到的企业 ID。 (您需要为客户创建服务帐户才能进行身份验证)。问题将会得到解决。

关于java - GoogleJsonResponseException : 404 Not Found during getting user list of enterprise,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32383354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com