GoogleApps 客户端仅提供 SocketTimeOutException
GoogleApps client giving SocketTimeOutException only
我们编写了一个客户端来使用 GoogleNetHttpTransport 在 googleapps 上创建用户,但是当通过 superadmin api 将用户设置为超级管理员时,我们收到了 socketTimeoutException。连接用户本身具有超级管理员权限。
如何在我们使用 GoogleNetHttpTransport 时增加 ReadTimeOut/SocketTimeout。请在下面找到有关连接到目标和制作客户端的代码片段
httpTransport = GoogleNetHttpTransport.newTrustedTransport() ;
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(serviceAccountId)
.setServiceAccountScopes(scopes)
.setServiceAccountUser(superAdminUserMail)
.setServiceAccountPrivateKeyFromP12File(privateKeyFile).build();
client = new Directory.Builder(httpTransport, JSON_FACTORY,credential)
.setApplicationName(APPLICATION_NAME).
.setHttpRequestInitializer(credential).build();
//Getting the sockt/timeout exception
client.users().makeAdmin(userID, admin).execute();
创建您自己的 HttpRequestInitializer:
new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
credential.initialize(request);
request.setConnectTimeout(CONNECT_TIMEOUT);
request.setReadTimeout(READ_TIMEOUT);
}
}
我们编写了一个客户端来使用 GoogleNetHttpTransport 在 googleapps 上创建用户,但是当通过 superadmin api 将用户设置为超级管理员时,我们收到了 socketTimeoutException。连接用户本身具有超级管理员权限。
如何在我们使用 GoogleNetHttpTransport 时增加 ReadTimeOut/SocketTimeout。请在下面找到有关连接到目标和制作客户端的代码片段
httpTransport = GoogleNetHttpTransport.newTrustedTransport() ;
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(serviceAccountId)
.setServiceAccountScopes(scopes)
.setServiceAccountUser(superAdminUserMail)
.setServiceAccountPrivateKeyFromP12File(privateKeyFile).build();
client = new Directory.Builder(httpTransport, JSON_FACTORY,credential)
.setApplicationName(APPLICATION_NAME).
.setHttpRequestInitializer(credential).build();
//Getting the sockt/timeout exception
client.users().makeAdmin(userID, admin).execute();
创建您自己的 HttpRequestInitializer:
new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
credential.initialize(request);
request.setConnectTimeout(CONNECT_TIMEOUT);
request.setReadTimeout(READ_TIMEOUT);
}
}