You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/*
* Create a service account and save the credentials json file
* https://console.cloud.google.com/projectselector2/apis/enableflow?authuser=1
*/
final File credentialsJsonFile = null; // TODO specify a credentials json file
/*
* Use ServiceAccountCredentials as the Credentials implementation
*/
final Credentials credentials;
try (final InputStream in = new FileInputStream(credentialsJsonFile)) {
credentials = ServiceAccountCredentials.fromStream(in);
}
/*
* Create the AnalyticsAdminServiceSettings
*/
final AnalyticsAdminServiceSettings analyticsAdminServiceSettings = AnalyticsAdminServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credentials))
.build();
/*
* Finally, create the AnalyticsAdminServiceClient
*/
final AnalyticsAdminServiceClient client = AnalyticsAdminServiceClient.create(analyticsAdminServiceSettings);
Create the API Secret
final DataStreamName dataStreamName = DataStreamName.newBuilder()
.setDataStream("123456") // replace with your datastream id
.setProperty("7654321") // replace with your property id
.build();
final MeasurementProtocolSecret secretName = MeasurementProtocolSecret.newBuilder()
.setDisplayName("orange") // replace with a name you want
.build();
final MeasurementProtocolSecret secret = client.createMeasurementProtocolSecret(dataStreamName, secretName);
final String apiSecret = secret.getSecretValue();
System.out.println("Here is your new api_secret: "+ apiSecret);