Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions docs/oauth-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ For instructions on setting up your credentials properly, see the
already have an access token, you can make a request in the following way:

```java
GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken);
Plus plus = new Plus.builder(new NetHttpTransport(),
JacksonFactory.getDefaultInstance(),
credential)
.setApplicationName("Google-PlusSample/1.0")
.build();
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();

GoogleCredentials googleCredentials = GoogleCredentials.create(access_token);
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(googleCredentials);

Storage storage = new Storage.Builder(httpTransport, jsonFactory, requestInitializer)
.setApplicationName("MyProject-1234")
.build();
```

### Google App Engine identity
Expand Down Expand Up @@ -345,20 +348,20 @@ end-user's data, Service Accounts provide access to the client application's
own data. Your client application signs the request for an access token using
a private key downloaded from the [Google API Console][console].

Example code taken from [plus-serviceaccount-cmdline-sample][plus-sample]:
For example, you can make a request in the following way:

```java
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
...
// Build service account credential.

GoogleCredential credential = GoogleCredential.fromStream(new FileInputStream("MyProject-1234.json"))
.createScoped(Collections.singleton(PlusScopes.PLUS_ME));
// Set up global Plus instance.
plus = new Plus.Builder(httpTransport, jsonFactory, credential)
.setApplicationName(APPLICATION_NAME).build();
...

//Build service account credential
GoogleCredentials googleCredentials = GoogleCredentials.
fromStream(new FileInputStream("/path/to/file"));
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(googleCredentials);

Storage storage = new Storage.Builder(httpTransport, jsonFactory, requestInitializer)
.setApplicationName("MyProject-1234")
.build();
```

For an additional sample, see [storage-serviceaccount-cmdline-sample][storage-sample].
Expand Down