Skip to content

Commit b70c3bc

Browse files
authored
Merge pull request #1 from googleanalytics/quickstart
docs: added quickstart .NET app
2 parents c058fb1 + 1242635 commit b70c3bc

3 files changed

Lines changed: 121 additions & 0 deletions

File tree

analytics-admin/AnalyticsAdmin.sln

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26124.0
5+
MinimumVisualStudioVersion = 15.0.26124.0
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickStart", "QuickStart\QuickStart.csproj", "{5ECD6AB3-9E95-46B2-8F11-BDDEC36CB0E7}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Debug|x64 = Debug|x64
12+
Debug|x86 = Debug|x86
13+
Release|Any CPU = Release|Any CPU
14+
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{5ECD6AB3-9E95-46B2-8F11-BDDEC36CB0E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{5ECD6AB3-9E95-46B2-8F11-BDDEC36CB0E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{5ECD6AB3-9E95-46B2-8F11-BDDEC36CB0E7}.Debug|x64.ActiveCfg = Debug|Any CPU
24+
{5ECD6AB3-9E95-46B2-8F11-BDDEC36CB0E7}.Debug|x64.Build.0 = Debug|Any CPU
25+
{5ECD6AB3-9E95-46B2-8F11-BDDEC36CB0E7}.Debug|x86.ActiveCfg = Debug|Any CPU
26+
{5ECD6AB3-9E95-46B2-8F11-BDDEC36CB0E7}.Debug|x86.Build.0 = Debug|Any CPU
27+
{5ECD6AB3-9E95-46B2-8F11-BDDEC36CB0E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{5ECD6AB3-9E95-46B2-8F11-BDDEC36CB0E7}.Release|Any CPU.Build.0 = Release|Any CPU
29+
{5ECD6AB3-9E95-46B2-8F11-BDDEC36CB0E7}.Release|x64.ActiveCfg = Release|Any CPU
30+
{5ECD6AB3-9E95-46B2-8F11-BDDEC36CB0E7}.Release|x64.Build.0 = Release|Any CPU
31+
{5ECD6AB3-9E95-46B2-8F11-BDDEC36CB0E7}.Release|x86.ActiveCfg = Release|Any CPU
32+
{5ECD6AB3-9E95-46B2-8F11-BDDEC36CB0E7}.Release|x86.Build.0 = Release|Any CPU
33+
EndGlobalSection
34+
EndGlobal
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright(c) 2020 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4+
// use this file except in compliance with the License. You may obtain a copy of
5+
// the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
// License for the specific language governing permissions and limitations under
13+
// the License.
14+
15+
/* Google Analytics Admin API sample quickstart application.
16+
17+
Example usage:
18+
dotnet restore
19+
dotnet run
20+
21+
This application demonstrates the usage of the Analytics Admin API using
22+
service account credentials. For more information on service accounts, see
23+
24+
https://cloud.google.com/iam/docs/understanding-service-accounts
25+
26+
The following document provides instructions on setting service account
27+
credentials for your application:
28+
29+
https://cloud.google.com/docs/authentication/production
30+
31+
In a nutshell, you need to:
32+
1. Create a service account and download the key JSON file.
33+
34+
https://cloud.google.com/docs/authentication/production#creating_a_service_account
35+
36+
2. Provide service account credentials using one of the following options:
37+
- set the GOOGLE_APPLICATION_CREDENTIALS environment variable, the API
38+
client will use the value of this variable to find the service account key
39+
JSON file.
40+
41+
https://cloud.google.com/docs/authentication/production#setting_the_environment_variable
42+
43+
OR
44+
- manually pass the path to the service account key JSON file to the API client
45+
by specifying the keyFilename parameter in the constructor:
46+
https://cloud.google.com/docs/authentication/production#passing_the_path_to_the_service_account_key_in_code
47+
48+
*/
49+
50+
// [START analyticsadmin_quickstart]
51+
52+
using Google.Analytics.Admin.V1Alpha;
53+
using System;
54+
55+
namespace AnalyticsSamples
56+
{
57+
class QuickStart
58+
{
59+
static void Main(string[] args)
60+
{
61+
var client = AnalyticsAdminServiceClient.Create();
62+
var response = client.ListAccounts( new ListAccountsRequest() );
63+
foreach( Account account in response )
64+
{
65+
Console.WriteLine("Account name: {0}", account.Name);
66+
Console.WriteLine("Display name: {0}", account.DisplayName);
67+
Console.WriteLine("Country code: {0}", account.CountryCode);
68+
Console.WriteLine("Update time: {0}", account.UpdateTime);
69+
Console.WriteLine("Create time: {0}", account.CreateTime);
70+
Console.WriteLine();
71+
}
72+
}
73+
}
74+
}
75+
// [END analyticsadmin_quickstart]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Google.Analytics.Admin.V1Alpha" Version="1.0.0-alpha01" />
10+
</ItemGroup>
11+
12+
</Project>

0 commit comments

Comments
 (0)