Skip to content

Commit 7435ba2

Browse files
authored
Set scopes of credentials read from JSON. (#17)
This is required for certain use cases including impersonated service account credentials.
1 parent 592468e commit 7435ba2

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

google-analytics-data/src/main/java/com/google/analytics/data/samples/QuickstartJsonCredentialsSample.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ static void sampleRunReport(String propertyId, String credentialsJsonPath) throw
6969
// Explicitly use service account credentials by specifying
7070
// the private key file.
7171
GoogleCredentials credentials =
72-
GoogleCredentials.fromStream(new FileInputStream(credentialsJsonPath));
72+
GoogleCredentials.fromStream(new FileInputStream(credentialsJsonPath))
73+
.createScoped(
74+
"https://www.googleapis.com/auth/analytics.readonly",
75+
"https://www.googleapis.com/auth/analytics");
7376

7477
BetaAnalyticsDataSettings betaAnalyticsDataSettings =
7578
BetaAnalyticsDataSettings.newBuilder()

0 commit comments

Comments
 (0)