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 1414 <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
1515 <project .http.version>1.19.0</project .http.version>
1616 <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>
1719 </properties >
1820
1921 <prerequisites >
Original file line number Diff line number Diff line change 2020import com .google .api .client .json .JsonFactory ;
2121import com .google .api .client .json .jackson2 .JacksonFactory ;
2222import com .google .api .services .storage .Storage ;
23+ import com .google .api .services .storage .StorageScopes ;
2324import com .google .api .services .storage .model .Bucket ;
2425import com .google .api .services .storage .model .ObjectAccessControl ;
2526import com .google .api .services .storage .model .Objects ;
@@ -61,6 +62,12 @@ public class StorageSample {
6162 private static Storage getService () throws IOException , GeneralSecurityException {
6263 if (null == storageService ) {
6364 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+ }
6471 HttpTransport httpTransport = GoogleNetHttpTransport .newTrustedTransport ();
6572 storageService = new Storage .Builder (httpTransport , JSON_FACTORY , credential )
6673 .setApplicationName (APPLICATION_NAME ).build ();
You can’t perform that action at this time.
0 commit comments