@@ -47,12 +47,15 @@ For instructions on setting up your credentials properly, see the
47
47
already have an access token, you can make a request in the following way:
48
48
49
49
``` java
50
- GoogleCredential credential = new GoogleCredential (). setAccessToken(accessToken);
51
- Plus plus = new Plus .builder(new NetHttpTransport (),
52
- JacksonFactory . getDefaultInstance(),
53
- credential)
54
- .setApplicationName(" Google-PlusSample/1.0" )
55
- .build();
50
+ HttpTransport httpTransport = GoogleNetHttpTransport . newTrustedTransport();
51
+ JsonFactory jsonFactory = JacksonFactory . getDefaultInstance();
52
+
53
+ GoogleCredentials googleCredentials = GoogleCredentials . create(access_token);
54
+ HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter (googleCredentials);
55
+
56
+ Storage storage = new Storage .Builder (httpTransport, jsonFactory, requestInitializer)
57
+ .setApplicationName(" MyProject-1234" )
58
+ .build();
56
59
```
57
60
58
61
### Google App Engine identity
@@ -345,20 +348,20 @@ end-user's data, Service Accounts provide access to the client application's
345
348
own data. Your client application signs the request for an access token using
346
349
a private key downloaded from the [ Google API Console] [ console ] .
347
350
348
- Example code taken from [ plus-serviceaccount-cmdline-sample ] [ plus-sample ] :
351
+ For example, you can make a request in the following way :
349
352
350
353
``` java
351
354
HttpTransport httpTransport = GoogleNetHttpTransport . newTrustedTransport();
352
355
JsonFactory jsonFactory = JacksonFactory . getDefaultInstance();
353
- ...
354
- // Build service account credential.
355
-
356
- GoogleCredential credential = GoogleCredential . fromStream(new FileInputStream (" MyProject-1234.json " ))
357
- .createScoped( Collections . singleton( PlusScopes . PLUS_ME ) );
358
- // Set up global Plus instance.
359
- plus = new Plus .Builder (httpTransport, jsonFactory, credential )
360
- .setApplicationName(APPLICATION_NAME ) . build();
361
- ...
356
+
357
+ // Build service account credential
358
+ GoogleCredentials googleCredentials = GoogleCredentials .
359
+ fromStream(new FileInputStream (" /path/to/file " ));
360
+ HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter (googleCredentials );
361
+
362
+ Storage storage = new Storage .Builder (httpTransport, jsonFactory, requestInitializer )
363
+ .setApplicationName(" MyProject-1234 " )
364
+ .build();
362
365
```
363
366
364
367
For an additional sample, see [ storage-serviceaccount-cmdline-sample] [ storage-sample ] .
0 commit comments