 <p>You will need to overwrite the "<strong>tokenServerEncodedUrl</strong>" parameter value in the GoogleCredential object, and "<strong>rootUrl</strong>" parameter value in the Directory object for using your non-standard SSH Tunnel Ports for GoogleAPI client communication.</p> <p>Use the following code snippet to achieve it:</p> <p>GoogleCredential credential = (new com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder()).setTransport(httpTransport).setJsonFactory(jsonFactory).<strong>setTokenServerUrl(new GenericUrl("<a href="https://accounts.google.com:ssh-port/o/oauth2/token" rel="nofollow">https://accounts.google.com:ssh-port/o/oauth2/token</a>"))</strong>.setServiceAccountUser(ACCT_USER).setServiceAccountId(ACCT_ID).setServiceAccountScopes(SCOPES).setServiceAccountPrivateKeyFromP12File(p12).build();</p> <p>Directory service = (new com.google.api.services.admin.directory.Directory.Builder(httpTransport, jsonFactory, null)).setHttpRequestInitializer(credential).<strong>setRootUrl("<a href="https://www.googleapis.com:22230/" rel="nofollow">https://www.googleapis.com:22230/</a>")</strong>.setApplicationName(APP_NAME).build();</p> <p>The above code snippet shall overwrite the default service URL values set by the Google API Client libraries (Jar files).</p>