Skip to content

Commit 1c6f936

Browse files
authored
Merge branch 'master' into patch-1
2 parents ba7e9df + 157ae04 commit 1c6f936

File tree

98 files changed

+28629
-627
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+28629
-627
lines changed

.github/ISSUE_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(Please search [existing issues](https://github.com/gsuitedevs/dotnet-samples/issues) before creating a new one.)
1+
(Please search [existing issues](https://github.com/googleworkspace/dotnet-samples/issues) before creating a new one.)
22

33
**Sample Name:**
44

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# G Suite .NET Samples [![Build Status](https://travis-ci.org/gsuitedevs/dotnet-samples.svg?branch=master)](https://travis-ci.org/gsuitedevs/dotnet-samples)
1+
# Google Workspace .NET Samples [![Build Status](https://travis-ci.org/googleworkspace/dotnet-samples.svg?branch=master)](https://travis-ci.org/googleworkspace/dotnet-samples)
22

3-
.NET samples for [G Suite API](https://developers.google.com/gsuite/) docs.
3+
.NET samples for [Google Workspace APIs](https://developers.google.com/gsuite/) docs.
44

55
## APIs
66

77
- [Classroom Quickstart](https://developers.google.com/classroom/quickstart/dotnet)
8-
- [Calendar Quickstart](https://developers.google.com/calendar/quickstart/dotnet)
9-
- [Drive V3 Quickstart](https://developers.google.com/drive/v3/web/quickstart/dotnet)
8+
- [Calendar Quickstart](https://developers.google.com/calendar/api/quickstart/dotnet)
9+
- [Drive V3 Quickstart](https://developers.google.com/drive/api/quickstart/dotnet)
1010
- [Gmail Quickstart](https://developers.google.com/gmail/api/quickstart/dotnet)
1111
- [Sheets Quickstart](https://developers.google.com/sheets/api/quickstart/dotnet)
1212
- [Slides Quickstart](https://developers.google.com/slides/quickstart/dotnet)
@@ -22,7 +22,7 @@
2222

2323
## .NET Client Library
2424

25-
G Suite APIs use the [Google API .NET client library](https://github.com/google/google-api-dotnet-client).
25+
Google Workspace APIs use the [Google API .NET client library](https://github.com/google/google-api-dotnet-client).
2626

2727
## Contributing
2828

adminSDK/directory/AdminSDKDirectoryQuickstart/AdminSDKDirectoryQuickstart.cs

+46-39
Original file line numberDiff line numberDiff line change
@@ -25,61 +25,68 @@
2525

2626
namespace AdminSDKDirectoryQuickstart
2727
{
28+
// Class to demonstrate the use of Directory users list API
2829
class Program
2930
{
30-
// If modifying these scopes, delete your previously saved credentials
31-
// at ~/.credentials/admin-directory_v1-dotnet-quickstart.json
31+
/* Global instance of the scopes required by this quickstart.
32+
If modifying these scopes, delete your previously saved token.json/ folder. */
3233
static string[] Scopes = { DirectoryService.Scope.AdminDirectoryUserReadonly };
3334
static string ApplicationName = "Directory API .NET Quickstart";
3435

3536
static void Main(string[] args)
3637
{
37-
UserCredential credential;
38-
39-
using (var stream =
40-
new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
38+
try
4139
{
42-
// The file token.json stores the user's access and refresh tokens, and is created
43-
// automatically when the authorization flow completes for the first time.
44-
string credPath = "token.json";
45-
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
46-
GoogleClientSecrets.Load(stream).Secrets,
47-
Scopes,
48-
"user",
49-
CancellationToken.None,
50-
new FileDataStore(credPath, true)).Result;
51-
Console.WriteLine("Credential file saved to: " + credPath);
52-
}
40+
UserCredential credential;
41+
// Load client secrets.
42+
using (var stream =
43+
new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
44+
{
45+
/* The file token.json stores the user's access and refresh tokens, and is created
46+
automatically when the authorization flow completes for the first time. */
47+
string credPath = "token.json";
48+
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
49+
GoogleClientSecrets.FromStream(stream).Secrets,
50+
Scopes,
51+
"user",
52+
CancellationToken.None,
53+
new FileDataStore(credPath, true)).Result;
54+
Console.WriteLine("Credential file saved to: " + credPath);
55+
}
5356

54-
// Create Directory API service.
55-
var service = new DirectoryService(new BaseClientService.Initializer()
56-
{
57-
HttpClientInitializer = credential,
58-
ApplicationName = ApplicationName,
59-
});
57+
// Create Directory API service.
58+
var service = new DirectoryService(new BaseClientService.Initializer
59+
{
60+
HttpClientInitializer = credential,
61+
ApplicationName = ApplicationName
62+
});
6063

61-
// Define parameters of request.
62-
UsersResource.ListRequest request = service.Users.List();
63-
request.Customer = "my_customer";
64-
request.MaxResults = 10;
65-
request.OrderBy = UsersResource.ListRequest.OrderByEnum.Email;
64+
// Define parameters of request.
65+
UsersResource.ListRequest request = service.Users.List();
66+
request.Customer = "my_customer";
67+
request.MaxResults = 10;
68+
request.OrderBy = UsersResource.ListRequest.OrderByEnum.Email;
6669

67-
// List users.
68-
IList<User> users = request.Execute().UsersValue;
69-
Console.WriteLine("Users:");
70-
if (users != null && users.Count > 0)
71-
{
72-
foreach (var userItem in users)
70+
// List users.
71+
IList<User> users = request.Execute().UsersValue;
72+
Console.WriteLine("Users:");
73+
if (users != null && users.Count > 0)
74+
{
75+
foreach (var userItem in users)
76+
{
77+
Console.WriteLine("{0} ({1})", userItem.PrimaryEmail,
78+
userItem.Name.FullName);
79+
}
80+
}
81+
else
7382
{
74-
Console.WriteLine("{0} ({1})", userItem.PrimaryEmail,
75-
userItem.Name.FullName);
83+
Console.WriteLine("No users found.");
7684
}
7785
}
78-
else
86+
catch (FileNotFoundException e)
7987
{
80-
Console.WriteLine("No users found.");
88+
Console.WriteLine(e.Message);
8189
}
82-
Console.Read();
8390
}
8491
}
8592
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp2.2</TargetFramework>
6-
</PropertyGroup>
7-
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
</PropertyGroup>
7+
88
<ItemGroup>
9-
<PackageReference Include="Google.Apis.Admin.Directory.directory_v1" Version="1.39.0.1505" />
10-
</ItemGroup>
11-
12-
</Project>
9+
<PackageReference Include="Google.Apis.Admin.Directory.directory_v1" Version="1.57.0.2640"/>
10+
</ItemGroup>
11+
12+
</Project>
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}") = "AdminSDKGroupsSettingsQuickstart", "AdminSDKGroupsSettingsQuickstart\AdminSDKGroupsSettingsQuickstart.csproj", "{A0E0373A-7A07-478E-AB2E-273EB47DF2E8}"
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+
{A0E0373A-7A07-478E-AB2E-273EB47DF2E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{A0E0373A-7A07-478E-AB2E-273EB47DF2E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{A0E0373A-7A07-478E-AB2E-273EB47DF2E8}.Debug|x64.ActiveCfg = Debug|Any CPU
24+
{A0E0373A-7A07-478E-AB2E-273EB47DF2E8}.Debug|x64.Build.0 = Debug|Any CPU
25+
{A0E0373A-7A07-478E-AB2E-273EB47DF2E8}.Debug|x86.ActiveCfg = Debug|Any CPU
26+
{A0E0373A-7A07-478E-AB2E-273EB47DF2E8}.Debug|x86.Build.0 = Debug|Any CPU
27+
{A0E0373A-7A07-478E-AB2E-273EB47DF2E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{A0E0373A-7A07-478E-AB2E-273EB47DF2E8}.Release|Any CPU.Build.0 = Release|Any CPU
29+
{A0E0373A-7A07-478E-AB2E-273EB47DF2E8}.Release|x64.ActiveCfg = Release|Any CPU
30+
{A0E0373A-7A07-478E-AB2E-273EB47DF2E8}.Release|x64.Build.0 = Release|Any CPU
31+
{A0E0373A-7A07-478E-AB2E-273EB47DF2E8}.Release|x86.ActiveCfg = Release|Any CPU
32+
{A0E0373A-7A07-478E-AB2E-273EB47DF2E8}.Release|x86.Build.0 = Release|Any CPU
33+
EndGlobalSection
34+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of 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,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// [START admin_sdk_groups_settings_quickstart]
16+
using Google.Apis.Auth.OAuth2;
17+
using Google.Apis.Groupssettings.v1;
18+
using Google.Apis.Services;
19+
using Google.Apis.Util.Store;
20+
using System;
21+
using System.IO;
22+
using System.Threading;
23+
using Groups = Google.Apis.Groupssettings.v1.Data.Groups;
24+
25+
namespace AdminSDKGroupsSettingsQuickstart
26+
{
27+
class Program
28+
{
29+
// If modifying these scopes, delete your previously saved credentials
30+
// at ~/.credentials/groupssettings_v1-dotnet-quickstart.json
31+
static string[] Scopes = { "https://www.googleapis.com/auth/apps.groups.settings"};
32+
static string ApplicationName = "Groups Settings API .NET Quickstart";
33+
34+
static void Main(string[] args)
35+
{
36+
UserCredential credential;
37+
38+
using (var stream =
39+
new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
40+
{
41+
// The file token.json stores the user's access and refresh tokens, and is created
42+
// automatically when the authorization flow completes for the first time.
43+
string credPath = "token.json";
44+
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
45+
GoogleClientSecrets.FromStream(stream).Secrets,
46+
Scopes,
47+
"user",
48+
CancellationToken.None,
49+
new FileDataStore(credPath, true)).Result;
50+
Console.WriteLine("Credential file saved to: {0}", credPath);
51+
}
52+
53+
// Create Directory API service.
54+
var service = new GroupssettingsService(new BaseClientService.Initializer()
55+
{
56+
HttpClientInitializer = credential,
57+
ApplicationName = ApplicationName,
58+
});
59+
60+
// Service ready to use
61+
62+
if (args.Length == 0)
63+
{
64+
Console.WriteLine("No group email specified.");
65+
return;
66+
}
67+
68+
String groupEmail = args[0];
69+
try
70+
{
71+
Groups settings = service.Groups.Get(groupEmail).Execute();
72+
Console.Write("Description: {0}", settings.Description);
73+
}
74+
catch (Exception err)
75+
{
76+
// TODO(developer) - handle exception
77+
Console.Error.WriteLine(err);
78+
}
79+
80+
}
81+
}
82+
}
83+
// [END admin_sdk_groups_settings_quickstart]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Google.Apis.Groupssettings.v1" Version="1.57.0.2366" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<None Remove="credentials.json" />
14+
<AdditionalFiles Include="credentials.json">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
</AdditionalFiles>
17+
</ItemGroup>
18+
19+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Google.Apis" version="1.33.1" targetFramework="net47" />
4+
<package id="Google.Apis.Groupssettings.v1" version="1.57.0.2366" targetFramework="net47" />
5+
<package id="Google.Apis.Auth" version="1.33.1" targetFramework="net47" />
6+
<package id="Google.Apis.Core" version="1.33.1" targetFramework="net47" />
7+
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net47" />
8+
<package id="System.IO" version="4.3.0" targetFramework="net47" />
9+
<package id="System.Net.Http" version="4.3.1" targetFramework="net47" />
10+
<package id="System.Runtime" version="4.3.0" targetFramework="net47" />
11+
<package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net47" />
12+
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net47" />
13+
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net47" />
14+
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net47" />
15+
</packages>

0 commit comments

Comments
 (0)