File tree Expand file tree Collapse file tree 2 files changed +9
-0
lines changed
storage/json-api/src/main/java Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change 14
14
<project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
15
15
<project .http.version>1.19.0</project .http.version>
16
16
<project .oauth.version>1.19.0</project .oauth.version>
17
+ <maven .compiler.target>1.7</maven .compiler.target>
18
+ <maven .compiler.source>1.7</maven .compiler.source>
17
19
</properties >
18
20
19
21
<prerequisites >
Original file line number Diff line number Diff line change 20
20
import com .google .api .client .json .JsonFactory ;
21
21
import com .google .api .client .json .jackson2 .JacksonFactory ;
22
22
import com .google .api .services .storage .Storage ;
23
+ import com .google .api .services .storage .StorageScopes ;
23
24
import com .google .api .services .storage .model .Bucket ;
24
25
import com .google .api .services .storage .model .ObjectAccessControl ;
25
26
import com .google .api .services .storage .model .Objects ;
@@ -61,6 +62,12 @@ public class StorageSample {
61
62
private static Storage getService () throws IOException , GeneralSecurityException {
62
63
if (null == storageService ) {
63
64
GoogleCredential credential = GoogleCredential .getApplicationDefault ();
65
+ // Depending on the environment that provides the default credentials (e.g. Compute Engine,
66
+ // App Engine), the credentials may require us to specify the scopes we need explicitly.
67
+ // Check for this case, and inject the Bigquery scope if required.
68
+ if (credential .createScopedRequired ()) {
69
+ credential = credential .createScoped (StorageScopes .all ());
70
+ }
64
71
HttpTransport httpTransport = GoogleNetHttpTransport .newTrustedTransport ();
65
72
storageService = new Storage .Builder (httpTransport , JSON_FACTORY , credential )
66
73
.setApplicationName (APPLICATION_NAME ).build ();
You can’t perform that action at this time.
0 commit comments