本文整理匯總了Java中com.google.api.client.json.jackson2.JacksonFactory類的典型用法代碼示例。如果您正苦於以下問題:Java JacksonFactory類的具體用法?Java JacksonFactory怎麽用?Java JacksonFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JacksonFactory類屬於com.google.api.client.json.jackson2包,在下文中一共展示了JacksonFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: performRequest
import com.google.api.client.json.jackson2.JacksonFactory; //導入依賴的package包/類
private static void performRequest(String accessToken, String refreshToken, String apiKey, String apiSecret) throws GeneralSecurityException, IOException, MessagingException {
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = new JacksonFactory();
final Credential credential = convertToGoogleCredential(accessToken, refreshToken, apiSecret, apiKey);
Builder builder = new Gmail.Builder(httpTransport, jsonFactory, credential);
builder.setApplicationName("OAuth API Sample");
Gmail gmail = builder.build();
MimeMessage content = createEmail("[email protected]", "[email protected]", "Test Email", "It works");
Message message = createMessageWithEmail(content);
gmail.users().messages().send("[email protected]", message).execute();
}
示例2: getCredential
import com.google.api.client.json.jackson2.JacksonFactory; //導入依賴的package包/類
public final Credential getCredential() {
if (googleCredential == null) {
try {
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
secureHttpTransport,
JacksonFactory.getDefaultInstance(),
googleSecrets,
requiredScopes)
.setAccessType("offline")
.setDataStoreFactory(new MemoryDataStoreFactory())
.build();
googleCredential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver())
.authorize("user");
} catch (IOException e) {
//Will not occur
logger.fatal(e);
throw new RuntimeException();
}
}
return googleCredential;
}
示例3: BigQueryExporter
import com.google.api.client.json.jackson2.JacksonFactory; //導入依賴的package包/類
public BigQueryExporter(BigQueryExporterConfiguration config) {
this.config = config;
this.checkedSchemas = new HashSet<String>();
this.existingSchemaMap = new HashMap<String, com.google.api.services.bigquery.model.TableSchema>();
HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential;
try {
credential = GoogleCredential.getApplicationDefault(transport,
jsonFactory);
} catch (IOException e) {
throw new RuntimeException(e);
}
if (credential.createScopedRequired()) {
credential = credential.createScoped(BigqueryScopes.all());
}
this.bq = new Bigquery.Builder(transport, jsonFactory, credential)
.setApplicationName(this.config.applicationName).build();
}
示例4: createAuthorizedClient
import com.google.api.client.json.jackson2.JacksonFactory; //導入依賴的package包/類
/**
* Creates an authorized CloudKMS client service using Application Default Credentials.
*
* @return an authorized CloudKMS client
* @throws IOException if there's an error getting the default credentials.
*/
public static CloudKMS createAuthorizedClient() throws IOException {
// Create the credential
HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
// Authorize the client using Application Default Credentials
// @see https://g.co/dv/identity/protocols/application-default-credentials
GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
// Depending on the environment that provides the default credentials (e.g. Compute Engine, App
// Engine), the credentials may require us to specify the scopes we need explicitly.
// Check for this case, and inject the scope if required.
if (credential.createScopedRequired()) {
credential = credential.createScoped(CloudKMSScopes.all());
}
return new CloudKMS.Builder(transport, jsonFactory, credential)
.setApplicationName("CloudKMS snippets")
.build();
}
示例5: authorize
import com.google.api.client.json.jackson2.JacksonFactory; //導入依賴的package包/類
private static void authorize(DataStoreFactory storeFactory, String userId) throws Exception {
// Depending on your application, there may be more appropriate ways of
// performing the authorization flow (such as on a servlet), see
// https://developers.google.com/api-client-library/java/google-api-java-client/oauth2#authorization_code_flow
// for more information.
GoogleAuthorizationCodeFlow authorizationFlow = new GoogleAuthorizationCodeFlow.Builder(
new NetHttpTransport(),
new JacksonFactory(),
CLIENT_ID,
CLIENT_SECRET,
Arrays.asList(SCOPE))
.setDataStoreFactory(storeFactory)
// Set the access type to offline so that the token can be refreshed.
// By default, the library will automatically refresh tokens when it
// can, but this can be turned off by setting
// api.dfp.refreshOAuth2Token=false in your ads.properties file.
.setAccessType("offline").build();
String authorizeUrl =
authorizationFlow.newAuthorizationUrl().setRedirectUri(CALLBACK_URL).build();
System.out.printf("Paste this url in your browser:%n%s%n", authorizeUrl);
// Wait for the authorization code.
System.out.println("Type the code you received here: ");
@SuppressWarnings("DefaultCharset") // Reading from stdin, so default charset is appropriate.
String authorizationCode = new BufferedReader(new InputStreamReader(System.in)).readLine();
// Authorize the OAuth2 token.
GoogleAuthorizationCodeTokenRequest tokenRequest =
authorizationFlow.newTokenRequest(authorizationCode);
tokenRequest.setRedirectUri(CALLBACK_URL);
GoogleTokenResponse tokenResponse = tokenRequest.execute();
// Store the credential for the user.
authorizationFlow.createAndStoreCredential(tokenResponse, userId);
}
示例6: getScriptService
import com.google.api.client.json.jackson2.JacksonFactory; //導入依賴的package包/類
@NotNull
public final Script getScriptService() {
@NotNull Script service = (Script) cacheClients.computeIfAbsent(Script.class,
(clazz) ->
new Script.Builder(
secureHttpTransport(),
JacksonFactory.getDefaultInstance(),
getCredential())
.setApplicationName(EventManager.getInstance().getName())
.setScriptRequestInitializer(new ScriptRequestInitializer(GoogleAPIToken.value()))
.setGoogleClientRequestInitializer(new ScriptRequestInitializer(GoogleAPIToken.value()))
.setHttpRequestInitializer(createHttpTimeout(getCredential(), 380000))
.build());
Timers.cacheCleanUpTimer().schedule(cacheClients, Script.class, service, 30, TimeUnit.MINUTES);
return service;
}
示例7: getSheetsService
import com.google.api.client.json.jackson2.JacksonFactory; //導入依賴的package包/類
@NotNull
public final Sheets getSheetsService() {
@NotNull Sheets service = (Sheets) cacheClients.computeIfAbsent(Sheets.class,
(clazz) ->
new Sheets.Builder(
secureHttpTransport(),
JacksonFactory.getDefaultInstance(),
getCredential())
.setApplicationName(EventManager.getInstance().getName())
.setSheetsRequestInitializer(new SheetsRequestInitializer(GoogleAPIToken.value()))
.setGoogleClientRequestInitializer(new SheetsRequestInitializer(GoogleAPIToken.value()))
.build());
Timers.cacheCleanUpTimer().schedule(cacheClients, Sheets.class, service, 30, TimeUnit.MINUTES);
return service;
}
示例8: getUrlShortenerService
import com.google.api.client.json.jackson2.JacksonFactory; //導入依賴的package包/類
@NotNull
public final Urlshortener getUrlShortenerService() {
@NotNull Urlshortener service = (Urlshortener) cacheClients.computeIfAbsent(Urlshortener.class,
(clazz) ->
new Urlshortener.Builder(
secureHttpTransport(),
JacksonFactory.getDefaultInstance(),
getCredential())
.setApplicationName(EventManager.getInstance().getName())
.setUrlshortenerRequestInitializer(new UrlshortenerRequestInitializer(GoogleAPIToken.value()))
.setGoogleClientRequestInitializer(new UrlshortenerRequestInitializer(GoogleAPIToken.value()))
.build());
Timers.cacheCleanUpTimer().schedule(cacheClients, Urlshortener.class, service, 30, TimeUnit.MINUTES);
return service;
}
示例9: getSurveyService
import com.google.api.client.json.jackson2.JacksonFactory; //導入依賴的package包/類
@NotNull
public final Surveys getSurveyService() {
@NotNull Surveys service = (Surveys) cacheClients.computeIfAbsent(Surveys.class,
(clazz) ->
new Surveys.Builder(
secureHttpTransport(),
JacksonFactory.getDefaultInstance(),
getCredential())
.setApplicationName(EventManager.getInstance().getName())
.setSurveysRequestInitializer(new SurveysRequestInitializer(GoogleAPIToken.value()))
.setGoogleClientRequestInitializer(new SurveysRequestInitializer(GoogleAPIToken.value()))
.build());
Timers.cacheCleanUpTimer().schedule(cacheClients, Urlshortener.class, service, 30, TimeUnit.MINUTES);
return service;
}
示例10: testSimpleRetry
import com.google.api.client.json.jackson2.JacksonFactory; //導入依賴的package包/類
public void testSimpleRetry() throws Exception {
FailThenSuccessBackoffTransport fakeTransport =
new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_SERVER_ERROR, 3);
MockGoogleCredential credential = RetryHttpInitializerWrapper.newMockCredentialBuilder()
.build();
MockSleeper mockSleeper = new MockSleeper();
RetryHttpInitializerWrapper retryHttpInitializerWrapper = new RetryHttpInitializerWrapper(credential, mockSleeper,
TimeValue.timeValueSeconds(5));
Compute client = new Compute.Builder(fakeTransport, new JacksonFactory(), null)
.setHttpRequestInitializer(retryHttpInitializerWrapper)
.setApplicationName("test")
.build();
HttpRequest request = client.getRequestFactory().buildRequest("Get", new GenericUrl("http://elasticsearch.com"), null);
HttpResponse response = request.execute();
assertThat(mockSleeper.getCount(), equalTo(3));
assertThat(response.getStatusCode(), equalTo(200));
}
示例11: testIOExceptionRetry
import com.google.api.client.json.jackson2.JacksonFactory; //導入依賴的package包/類
public void testIOExceptionRetry() throws Exception {
FailThenSuccessBackoffTransport fakeTransport =
new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_SERVER_ERROR, 1, true);
MockGoogleCredential credential = RetryHttpInitializerWrapper.newMockCredentialBuilder()
.build();
MockSleeper mockSleeper = new MockSleeper();
RetryHttpInitializerWrapper retryHttpInitializerWrapper = new RetryHttpInitializerWrapper(credential, mockSleeper,
TimeValue.timeValueMillis(500));
Compute client = new Compute.Builder(fakeTransport, new JacksonFactory(), null)
.setHttpRequestInitializer(retryHttpInitializerWrapper)
.setApplicationName("test")
.build();
HttpRequest request = client.getRequestFactory().buildRequest("Get", new GenericUrl("http://elasticsearch.com"), null);
HttpResponse response = request.execute();
assertThat(mockSleeper.getCount(), equalTo(1));
assertThat(response.getStatusCode(), equalTo(200));
}
示例12: getTubeService
import com.google.api.client.json.jackson2.JacksonFactory; //導入依賴的package包/類
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;
}
示例13: GoogleConnector
import com.google.api.client.json.jackson2.JacksonFactory; //導入依賴的package包/類
/**
* Instances the google connector configuring all required resources.
*/
private GoogleConnector() throws IOException, GeneralSecurityException {
super();
// 1. JSON library
jsonFactory = JacksonFactory.getDefaultInstance();
// 2. Configure HTTP transport
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
// 3. Load the credentials
secrets = GoogleClientSecrets.load(jsonFactory, new InputStreamReader(GoogleConnector.class.getResourceAsStream("client-secrets.json")));
// 4. Configure the authentication flow
dataStoreFactory = new FileDataStoreFactory(CREDENTIALS_DIRECTORY);
// 5. Create flow
imp_buildAuthorizationFlow();
}
示例14: YouTubeSingleton
import com.google.api.client.json.jackson2.JacksonFactory; //導入依賴的package包/類
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();
}
示例15: getProjectsApiStub
import com.google.api.client.json.jackson2.JacksonFactory; //導入依賴的package包/類
/**
* Return the Projects api object used for accessing the Cloud Resource Manager Projects API.
* @return Projects api object used for accessing the Cloud Resource Manager Projects API
* @throws GeneralSecurityException Thrown if there's a permissions error.
* @throws IOException Thrown if there's an IO error initializing the API object.
*/
public static synchronized Projects getProjectsApiStub()
throws GeneralSecurityException, IOException {
if (projectApiStub != null) {
return projectApiStub;
}
HttpTransport transport;
GoogleCredential credential;
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
transport = GoogleNetHttpTransport.newTrustedTransport();
credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
if (credential.createScopedRequired()) {
Collection<String> scopes = CloudResourceManagerScopes.all();
credential = credential.createScoped(scopes);
}
projectApiStub = new CloudResourceManager
.Builder(transport, jsonFactory, credential)
.build()
.projects();
return projectApiStub;
}