-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathQuickStart.cs
More file actions
78 lines (63 loc) · 2.76 KB
/
QuickStart.cs
File metadata and controls
78 lines (63 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright(c) 2020 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
/* Google Analytics Admin API sample quickstart application.
Example usage:
dotnet restore
dotnet run
This application demonstrates the usage of the Analytics Admin API using
service account credentials. For more information on service accounts, see
https://cloud.google.com/iam/docs/understanding-service-accounts
The following document provides instructions on setting service account
credentials for your application:
https://cloud.google.com/docs/authentication/production
In a nutshell, you need to:
1. Create a service account and download the key JSON file.
https://cloud.google.com/docs/authentication/production#creating_a_service_account
2. Provide service account credentials using one of the following options:
- set the GOOGLE_APPLICATION_CREDENTIALS environment variable, the API
client will use the value of this variable to find the service account key
JSON file.
https://cloud.google.com/docs/authentication/production#setting_the_environment_variable
OR
- manually pass the path to the service account key JSON file to the API client
by specifying the keyFilename parameter in the constructor:
https://cloud.google.com/docs/authentication/production#passing_the_path_to_the_service_account_key_in_code
*/
// [START analyticsadmin_quickstart]
using System;
using Google.Analytics.Admin.V1Beta;
using Google.Api.Gax;
namespace AnalyticsSamples
{
class QuickStart
{
static void Main(string[] args)
{
AnalyticsAdminServiceClient client = AnalyticsAdminServiceClient.Create();
PagedEnumerable<ListAccountsResponse, Account> response = client.ListAccounts(
new ListAccountsRequest()
);
foreach (Account account in response)
{
Console.WriteLine("Account name: {0}", account.Name);
Console.WriteLine("Display name: {0}", account.DisplayName);
Console.WriteLine("Region code: {0}", account.RegionCode);
Console.WriteLine("Update time: {0}", account.UpdateTime);
Console.WriteLine("Create time: {0}", account.CreateTime);
Console.WriteLine();
}
}
}
}
// [END analyticsadmin_quickstart]