/** Builds a new Pubsub client and returns it. */ public static Pubsub getClient(final HttpTransport httpTransport, final JsonFactory jsonFactory) throws IOException { checkNotNull(httpTransport); checkNotNull(jsonFactory); GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport, jsonFactory); if (credential.createScopedRequired()) { credential = credential.createScoped(PubsubScopes.all()); } if (credential.getClientAuthentication() != null) { System.out.println( "\n***Warning! You are not using service account credentials to " + "authenticate.\nYou need to use service account credentials for this example," + "\nsince user-level credentials do not have enough pubsub quota,\nand so you will run " + "out of PubSub quota very quickly.\nSee " + "https://developers.google.com/identity/protocols/application-default-credentials."); System.exit(1); } HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential); return new Pubsub.Builder(httpTransport, jsonFactory, initializer) .setApplicationName(APP_NAME) .build(); }
/** * Builds a new Pubsub client and returns it. */ public static Pubsub getClient(final HttpTransport httpTransport, final JsonFactory jsonFactory) throws IOException { checkNotNull(httpTransport); checkNotNull(jsonFactory); GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport, jsonFactory); if (credential.createScopedRequired()) { credential = credential.createScoped(PubsubScopes.all()); } if (credential.getClientAuthentication() != null) { System.out.println("\n***Warning! You are not using service account credentials to " + "authenticate.\nYou need to use service account credentials for this example," + "\nsince user-level credentials do not have enough pubsub quota,\nand so you will run " + "out of PubSub quota very quickly.\nSee " + "https://developers.google.com/identity/protocols/application-default-credentials."); System.exit(1); } HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential); return new Pubsub.Builder(httpTransport, jsonFactory, initializer) .setApplicationName(APP_NAME) .build(); }
private synchronized YouTube getTubeService() { if( tubeService == null ) { tubeService = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), new HttpRequestInitializer() { @Override public void initialize(HttpRequest request) throws IOException { // Nothing? } }).setApplicationName(EQUELLA).build(); } return tubeService; }
@Override protected Drive connect(final HostKeyCallback callback, final LoginCallback prompt) { authorizationService = new OAuth2RequestInterceptor(builder.build(this, prompt).build(), host.getProtocol()) .withRedirectUri(host.getProtocol().getOAuthRedirectUrl()); final HttpClientBuilder configuration = builder.build(this, prompt); configuration.addInterceptorLast(authorizationService); configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(authorizationService)); this.transport = new ApacheHttpTransport(configuration.build()); return new Drive.Builder(transport, json, new HttpRequestInitializer() { @Override public void initialize(HttpRequest request) throws IOException { request.setSuppressUserAgentSuffix(true); // OAuth Bearer added in interceptor } }) .setApplicationName(useragent.get()) .build(); }
private YouTubeSingleton() { credential = GoogleAccountCredential.usingOAuth2( YTApplication.getAppContext(), Arrays.asList(SCOPES)) .setBackOff(new ExponentialBackOff()); youTube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), new HttpRequestInitializer() { @Override public void initialize(HttpRequest httpRequest) throws IOException { } }).setApplicationName(YTApplication.getAppContext().getString(R.string.app_name)) .build(); youTubeWithCredentials = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), credential) .setApplicationName(YTApplication.getAppContext().getString(R.string.app_name)) .build(); }
@VisibleForTesting ServiceConfigSupplier( Environment environment, HttpTransport httpTransport, JsonFactory jsonFactory, final GoogleCredential credential) { this.environment = environment; HttpRequestInitializer requestInitializer = new HttpRequestInitializer() { @Override public void initialize(HttpRequest request) throws IOException { request.setThrowExceptionOnExecuteError(false); credential.initialize(request); } }; this.serviceManagement = new ServiceManagement.Builder(httpTransport, jsonFactory, requestInitializer) .setApplicationName("Endpoints Frameworks Java") .build(); }
private YouTubeSingleton(Context context) { String appName = context.getString(R.string.app_name); credential = GoogleAccountCredential .usingOAuth2(context, Arrays.asList(SCOPES)) .setBackOff(new ExponentialBackOff()); youTube = new YouTube.Builder( new NetHttpTransport(), new JacksonFactory(), new HttpRequestInitializer() { @Override public void initialize(HttpRequest httpRequest) throws IOException {} } ).setApplicationName(appName).build(); youTubeWithCredentials = new YouTube.Builder( new NetHttpTransport(), new JacksonFactory(), credential ).setApplicationName(appName).build(); }
/** * Get an instance of the language service. * * @param document * @return */ public CloudNaturalLanguageAPI getApiService(GoogleCredential credential) { final GoogleCredential cred = credential; CloudNaturalLanguageAPI api = null; try { api = new CloudNaturalLanguageAPI.Builder( GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), new HttpRequestInitializer() { @Override public void initialize(HttpRequest httpRequest) throws IOException { cred.initialize(httpRequest); } }).setApplicationName(getApplicationName()).build(); } catch (Exception ex) { throw new GateRuntimeException("Could not establish Google Service API", ex); } //System.err.println("DEBUG: API instance established: " + api); return api; }
@Bean public Storage googleStorage() { JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); String applicationName = "Spinnaker/Halyard"; HttpRequestInitializer requestInitializer; try { requestInitializer = GoogleCredentials.setHttpTimeout(GoogleCredential.getApplicationDefault()); log.info("Loaded application default credential for reading BOMs & profiles."); } catch (Exception e) { requestInitializer = GoogleCredentials.retryRequestInitializer(); log.debug("No application default credential could be loaded for reading BOMs & profiles. Continuing unauthenticated: {}", e.getMessage()); } return new Storage.Builder(GoogleCredentials.buildHttpTransport(), jsonFactory, requestInitializer) .setApplicationName(applicationName) .build(); }
@Provides static Dns provideDns( HttpTransport transport, JsonFactory jsonFactory, Function<Set<String>, ? extends HttpRequestInitializer> credential, @Config("projectId") String projectId, @Config("cloudDnsRootUrl") Optional<String> rootUrl, @Config("cloudDnsServicePath") Optional<String> servicePath) { Dns.Builder builder = new Dns.Builder(transport, jsonFactory, credential.apply(DnsScopes.all())) .setApplicationName(projectId); rootUrl.ifPresent(builder::setRootUrl); servicePath.ifPresent(builder::setServicePath); return builder.build(); }
@Before public void before() throws Exception { when(subfactory.create( anyString(), any(HttpTransport.class), any(JsonFactory.class), any(HttpRequestInitializer.class))) .thenReturn(bigquery); when(bigquery.datasets()).thenReturn(bigqueryDatasets); when(bigqueryDatasets.insert(eq("Project-Id"), any(Dataset.class))) .thenReturn(bigqueryDatasetsInsert); when(bigquery.tables()).thenReturn(bigqueryTables); when(bigqueryTables.insert(eq("Project-Id"), any(String.class), any(Table.class))) .thenReturn(bigqueryTablesInsert); factory = new BigqueryFactory(); factory.subfactory = subfactory; factory.bigquerySchemas = new ImmutableMap.Builder<String, ImmutableList<TableFieldSchema>>() .put( "Table-Id", ImmutableList.of(new TableFieldSchema().setName("column1").setType(STRING.name()))) .put( "Table2", ImmutableList.of(new TableFieldSchema().setName("column1").setType(STRING.name()))) .build(); }
@Before public void setup() throws Exception { when(bigqueryFactory.create(anyString(), anyString(), anyString())).thenReturn(bigquery); when(bigqueryFactory.create( anyString(), Matchers.any(HttpTransport.class), Matchers.any(JsonFactory.class), Matchers.any(HttpRequestInitializer.class))) .thenReturn(bigquery); when(bigquery.tabledata()).thenReturn(tabledata); when(tabledata.insertAll( anyString(), anyString(), anyString(), Matchers.any(TableDataInsertAllRequest.class))).thenReturn(insertAll); action = new MetricsExportAction(); action.bigqueryFactory = bigqueryFactory; action.insertId = "insert id"; action.parameters = parameters; action.projectId = "project id"; action.tableId = "eppMetrics"; }
public static Tasks getGoogleTasksService(final Context context, String accountName) { final GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, ListManager.TASKS_SCOPES); credential.setSelectedAccountName(accountName); Tasks googleService = new Tasks.Builder(TRANSPORT, JSON_FACTORY, credential) .setApplicationName(DateUtils.getAppName(context)) .setHttpRequestInitializer(new HttpRequestInitializer() { @Override public void initialize(HttpRequest httpRequest) { credential.initialize(httpRequest); httpRequest.setConnectTimeout(3 * 1000); // 3 seconds connect timeout httpRequest.setReadTimeout(3 * 1000); // 3 seconds read timeout } }) .build(); return googleService; }
/** * Constructor that will automatically instantiate a Google Cloud Pub/Sub instance. * * @throws IOException when the initialization of the Google Cloud Pub/Sub client fails. */ public GcloudPubsub() throws IOException { if (CLOUD_PUBSUB_PROJECT_ID == null) { throw new IllegalStateException(GCLOUD_PUBSUB_PROJECT_ID_NOT_SET_ERROR); } try { serverName = InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException e) { throw new IllegalStateException("Unable to retrieve the hostname of the system"); } HttpTransport httpTransport = checkNotNull(Utils.getDefaultTransport()); JsonFactory jsonFactory = checkNotNull(Utils.getDefaultJsonFactory()); GoogleCredential credential = GoogleCredential.getApplicationDefault( httpTransport, jsonFactory); if (credential.createScopedRequired()) { credential = credential.createScoped(PubsubScopes.all()); } HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential); pubsub = new Pubsub.Builder(httpTransport, jsonFactory, initializer).build(); logger.info("Google Cloud Pub/Sub Initialization SUCCESS"); }
public YouTubeRetriever(Credentials credentials) throws Exception { super(credentials); if (credentials.getClientId() == null || credentials.getKey() == null) { logger.error("YouTube requires authentication."); throw new Exception("YouTube requires authentication."); } apiKey = credentials.getKey(); youtube = new YouTube.Builder( HTTP_TRANSPORT, JSON_FACTORY, new HttpRequestInitializer() { public void initialize(HttpRequest request) throws IOException { } } ).setApplicationName(credentials.getClientId()).build(); }
/** * Create a Storage Transfer client using user-supplied credentials and other settings. * * @param httpTransport * a user-supplied HttpTransport * @param jsonFactory * a user-supplied JsonFactory * @param credential * a user-supplied Google credential * @return a Storage Transfer client */ public static Storagetransfer createStorageTransferClient( HttpTransport httpTransport, JsonFactory jsonFactory, GoogleCredential credential) { Preconditions.checkNotNull(httpTransport); Preconditions.checkNotNull(jsonFactory); Preconditions.checkNotNull(credential); // In some cases, you need to add the scope explicitly. if (credential.createScopedRequired()) { credential = credential.createScoped(StoragetransferScopes.all()); } // Please use custom HttpRequestInitializer for automatic // retry upon failures. We provide a simple reference // implementation in the "Retry Handling" section. HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential); return new Storagetransfer.Builder(httpTransport, jsonFactory, initializer) .setApplicationName("storagetransfer-sample") .build(); }
/** Delete this registry from Cloud IoT. */ public static void deleteRegistry(String cloudRegion, String projectId, String registryName) throws GeneralSecurityException, IOException { GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all()); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential); final CloudIot service = new CloudIot.Builder( GoogleNetHttpTransport.newTrustedTransport(),jsonFactory, init) .setApplicationName(APP_NAME).build(); final String registryPath = String.format("projects/%s/locations/%s/registries/%s", projectId, cloudRegion, registryName); System.out.println("Deleting: " + registryPath); service.projects().locations().registries().delete(registryPath).execute(); }
/** Delete the given device from the registry. */ public static void deleteDevice(String deviceId, String projectId, String cloudRegion, String registryName) throws GeneralSecurityException, IOException { GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all()); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential); final CloudIot service = new CloudIot.Builder( GoogleNetHttpTransport.newTrustedTransport(),jsonFactory, init) .setApplicationName(APP_NAME).build(); final String devicePath = String.format("projects/%s/locations/%s/registries/%s/devices/%s", projectId, cloudRegion, registryName, deviceId); System.out.println("Deleting device " + devicePath); service.projects().locations().registries().devices().delete(devicePath).execute(); }
/** Retrieves device metadata from a registry. **/ public static Device getDevice(String deviceId, String projectId, String cloudRegion, String registryName) throws GeneralSecurityException, IOException { GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all()); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential); final CloudIot service = new CloudIot.Builder( GoogleNetHttpTransport.newTrustedTransport(),jsonFactory, init) .setApplicationName(APP_NAME).build(); final String devicePath = String.format("projects/%s/locations/%s/registries/%s/devices/%s", projectId, cloudRegion, registryName, deviceId); System.out.println("Retrieving device " + devicePath); return service.projects().locations().registries().devices().get(devicePath).execute(); }
/** Retrieves registry metadata from a project. **/ public static DeviceRegistry getRegistry( String projectId, String cloudRegion, String registryName) throws GeneralSecurityException, IOException { GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all()); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential); final CloudIot service = new CloudIot.Builder( GoogleNetHttpTransport.newTrustedTransport(),jsonFactory, init) .setApplicationName(APP_NAME).build(); final String registryPath = String.format("projects/%s/locations/%s/registries/%s", projectId, cloudRegion, registryName); return service.projects().locations().registries().get(registryPath).execute(); }
public YoutubeConnector(Context context) { youtube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), new HttpRequestInitializer() { @Override public void initialize(HttpRequest hr) throws IOException {} }).setApplicationName(context.getString(R.string.app_name)).build(); try{ // Setting search query query = youtube.search().list("id,snippet"); query.setKey(KEY); query.setType("video"); query.setFields("items(id/videoId,snippet/title,snippet/description,snippet/thumbnails/default/url)"); }catch(IOException e){ query = null; } }
/** * Builds a new Pubsub client and returns it. * * @param httpTransport HttpTransport for Pubsub client. * @param jsonFactory JsonFactory for Pubsub client. * @return Pubsub client. * @throws IOException when we can not get the default credentials. */ public static Pubsub getClient(final HttpTransport httpTransport, final JsonFactory jsonFactory) throws IOException { Preconditions.checkNotNull(httpTransport); Preconditions.checkNotNull(jsonFactory); GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport, jsonFactory); if (credential.createScopedRequired()) { credential = credential.createScoped(PubsubScopes.all()); } // Please use custom HttpRequestInitializer for automatic // retry upon failures. HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential); return new Pubsub.Builder(httpTransport, jsonFactory, initializer) .setApplicationName(APP_NAME) .build(); }
/** * Builds a new Pubsub client and returns it. * * @param httpTransport HttpTransport for Pubsub client. * @param jsonFactory JsonFactory for Pubsub client. * @return Pubsub client. * @throws IOException when we can not get the default credentials. */ public static Pubsub getClient(final HttpTransport httpTransport, final JsonFactory jsonFactory) throws IOException { Preconditions.checkNotNull(httpTransport); Preconditions.checkNotNull(jsonFactory); GoogleCredential credential = GoogleCredential.getApplicationDefault(); if (credential.createScopedRequired()) { credential = credential.createScoped(PubsubScopes.all()); } // Please use custom HttpRequestInitializer for automatic // retry upon failures. HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential); return new Pubsub.Builder(httpTransport, jsonFactory, initializer) .setApplicationName(APPLICATION_NAME) .build(); }
private Mobilebackend getMBSEndpoint() { // check if credential has account name final GoogleAccountCredential gac = mCredential == null || mCredential.getSelectedAccountName() == null ? null : mCredential; // create HttpRequestInitializer HttpRequestInitializer hri = new HttpRequestInitializer() { @Override public void initialize(HttpRequest request) throws IOException { request.setBackOffPolicy(new ExponentialBackOffPolicy()); if (gac != null) { gac.initialize(request); } } }; // build MBS builder // (specify gac or hri as the third parameter) return new Mobilebackend.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), hri) .setRootUrl(Consts.ENDPOINT_ROOT_URL).build(); }
private static HttpRequestInitializer setHttpBackoffTimeout(final HttpRequestInitializer requestInitializer, final int connectTimeoutMs, final int readTimeoutMs) { return new HttpRequestInitializer() { @Override public void initialize(HttpRequest httpRequest) throws IOException { requestInitializer.initialize(httpRequest); // Configure exponential backoff on error // https://developers.google.com/api-client-library/java/google-http-java-client/backoff ExponentialBackOff backoff = new ExponentialBackOff(); HttpUnsuccessfulResponseHandler backoffHandler = new HttpBackOffUnsuccessfulResponseHandler(backoff) .setBackOffRequired(HttpBackOffUnsuccessfulResponseHandler.BackOffRequired.ALWAYS); httpRequest.setUnsuccessfulResponseHandler(backoffHandler); httpRequest.setConnectTimeout(connectTimeoutMs); httpRequest.setReadTimeout(readTimeoutMs); } }; }
private void createClient() { try { final GoogleCredential credential = new GoogleCredential.Builder().setTransport(TRANSPORT) .setJsonFactory(JSON_FACTORY) .setServiceAccountId(serviceAccountId) .setServiceAccountScopes(Collections.singleton(SCOPE)) .setServiceAccountPrivateKeyFromP12File(new File(serviceAccountPrivateKeyFromP12File)) .setRequestInitializer(new HttpRequestInitializer() { @Override public void initialize(HttpRequest httpRequest) throws IOException { httpRequest.setConnectTimeout(connectTimeoutMs); httpRequest.setReadTimeout(readTimeoutMs); } }).build(); Bigquery.Builder builder = new Bigquery.Builder(TRANSPORT, JSON_FACTORY, credential).setApplicationName("BigQuery-Service-Accounts/0.1"); bigquery = builder.build(); } catch (Exception ex) { throw new ConfigurationException("Error creating bigquery client: " + ex.getMessage(), ex); } }
@Test public void testDescribeRequestAndResponseForApiClient() throws Exception { HttpRequestInitializer initializer = mock(HttpRequestInitializer.class); NetHttpTransport transport = new NetHttpTransport(); Storage storage = new Storage.Builder(transport, new JacksonFactory(), initializer) .setApplicationName("bla").build(); HttpRequest request = storage.objects().delete("bucket", "object").buildHttpRequest(); request.getHeaders().clear(); request.getHeaders().put("k1", "v1"); request.getHeaders().put("k2", "v2"); HttpResponseException exception = null; try { request.execute(); } catch (HttpResponseException ex) { exception = ex; } String expected = "Request: DELETE " + Storage.DEFAULT_BASE_URL + "b/bucket/o/object\n" + "k1: v1\nk2: v2\n\nno content\n\nResponse: 40"; String result = URLFetchUtils.describeRequestAndResponse(new HTTPRequestInfo(request), exception); assertTrue(expected + "\nis not a prefix of:\n" + result, result.startsWith(expected)); }
private <T extends AbstractGoogleJsonClient.Builder> T prepareBuilder(T builder, final HttpRequestInitializer delegate, GoogleClientRequestInitializer googleClientRequestInitializer) { builder .setHttpRequestInitializer(getHttpRequestInitializer(delegate)) .setApplicationName(applicationName) .setGoogleClientRequestInitializer(googleClientRequestInitializer); if (rootUrl.isPresent()) { builder.setRootUrl(rootUrl.get()); } if (servicePath.isPresent()) { builder.setServicePath(servicePath.get()); } return builder; }
private Mobilebackend getMBSEndpoint() { // check if credential has account name final GoogleAccountCredential gac = credential == null || credential.getSelectedAccountName() == null ? null : credential; // create HttpRequestInitializer HttpRequestInitializer hri = new HttpRequestInitializer() { @Override public void initialize(HttpRequest request) throws IOException { request.setBackOffPolicy(new ExponentialBackOffPolicy()); if (gac != null) { gac.initialize(request); } } }; // build MBS builder // (specify gac or hri as the third parameter) return new Mobilebackend.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), hri) .setRootUrl(Consts.ENDPOINT_ROOT_URL).build(); }
private Mobilebackend getMBSEndpoint() { // check if credential has account name final GoogleAccountCredential gac = credential == null || credential.getSelectedAccountName() == null ? null : credential; // create HttpRequestInitializer HttpRequestInitializer hri = new HttpRequestInitializer() { @Override public void initialize(HttpRequest request) throws IOException { request.setBackOffPolicy(new ExponentialBackOffPolicy()); if (gac != null) { gac.initialize(request); } } }; // build MBS builder // (specify gac or hri as the third parameter) return new Mobilebackend.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), hri).setRootUrl( Consts.ENDPOINT_ROOT_URL).build(); }
public YouTube youTube() { if (youTube == null) { try { HttpRequestInitializer credentials; if (mUseAuthCredentials) credentials = Auth.getCredentials(mContext, mUseDefaultAccount); else credentials = Auth.nullCredentials(mContext); youTube = new YouTube.Builder(new NetHttpTransport(), new AndroidJsonFactory(), credentials).setApplicationName("YouTubeAPI") .build(); } catch (Exception e) { e.printStackTrace(); } catch (Throwable t) { t.printStackTrace(); } } return youTube; }
public DevShopAccessService(String shopAdminUrl, String apiKey, String password) { this.baseShopUrl = shopAdminUrl; this.apiKey = apiKey; this.password = password; // Initial Request Factory // _requestFactory = HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() { @Override public void initialize(HttpRequest request) { //request.getHeaders().put("Content-Type", "application/json"); // Only an option if we plan to parse stream from the // stream. //request.setParser((new JsonObjectParser(JSON_FACTORY)); } }); String authStr = this.apiKey + ":" + this.password; encodedAuthentication = Base64.encodeBase64String(authStr.getBytes()); }
/** * Gets the report HTTP URL connection given report URL and proper information needed to * authenticate the request. * * @param reportUrl the URL of the report response or download * @return the report HTTP URL connection * @throws AuthenticationException If OAuth authorization fails. */ @VisibleForTesting HttpRequestFactory getHttpRequestFactory(final String reportUrl, String version) throws AuthenticationException { final HttpHeaders httpHeaders = createHeaders(reportUrl, version); return httpTransport.createRequestFactory(new HttpRequestInitializer() { @Override public void initialize(HttpRequest request) throws IOException { request.setHeaders(httpHeaders); request.setConnectTimeout(reportDownloadTimeout); request.setReadTimeout(reportDownloadTimeout); request.setThrowExceptionOnExecuteError(false); request.setLoggingEnabled(true); request.setResponseInterceptor(responseInterceptor); } }); }
@Override public AuthorizationCodeTokenRequest newTokenRequest(String authorizationCode) { return new LenientAuthorizationCodeTokenRequest(getTransport(), getJsonFactory(), new GenericUrl(getTokenServerEncodedUrl()), authorizationCode) .setClientAuthentication(getClientAuthentication()) .setScopes(getScopes()) .setRequestInitializer( new HttpRequestInitializer() { @Override public void initialize(HttpRequest request) throws IOException { HttpRequestInitializer requestInitializer = getRequestInitializer(); // If HttpRequestInitializer is set, initialize it as before if (requestInitializer != null) { requestInitializer.initialize(request); } // Also set JSON accept header request.getHeaders().setAccept("application/json"); } }); }