问题描述
我们使用GoogleNetHttpTransport编写了一个客户端来在googleapp上创建一个用户,但是当通过superadmin api将用户设置为超级管理员时,我们得到了一个socketTimeoutException。连接用户拥有superAdmin权限。
We wrote a client to create a user on googleapps using the GoogleNetHttpTransport, but we are getting a socketTimeoutException when making the user as Super Admin through superadmin api. Connecting User has superAdmin Privileges itself.
当我们使用GoogleNetHttpTransport时,如何增加ReadTimeOut / SocketTimeout 。请在下面的代码片段中找到关于连接目标和制作客户端的信息。
How to increase the ReadTimeOut/SocketTimeout when we are using the GoogleNetHttpTransport. Please find below code snippent on connecting to target and making the client
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:
Create your own HttpRequestInitializer:
new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
credential.initialize(request);
request.setConnectTimeout(CONNECT_TIMEOUT);
request.setReadTimeout(READ_TIMEOUT);
}
}
这篇关于仅适用于SocketTimeOutException的GoogleApps客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!