Skip to content

Instantly share code, notes, and snippets.

@tac-ljustiniano
Last active August 27, 2022 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tac-ljustiniano/69a374543c953d0206078dc22d094d22 to your computer and use it in GitHub Desktop.
Save tac-ljustiniano/69a374543c953d0206078dc22d094d22 to your computer and use it in GitHub Desktop.
Connecting to Google
using Google.Apis.Auth.OAuth2;
using Google.Apis.Admin.Directory.directory_v1;
using Google.Apis.Admin.Directory.directory_v1.Data;
using Google.Apis.Services;
...
string[] extScopes = {
DirectoryService.Scope.AdminDirectoryUserReadonly,
DirectoryService.Scope.AdminDirectoryGroupMemberReadonly
};
...
// JSON Example
GoogleCredential credential;
//cert: Attached Private Key File fileInfo.BinData
using (var stream = new MemoryStream(cert))
{
credential = GoogleCredential.FromStream(stream)
.CreateScoped(extScopes));
}
credential = credential.CreateWithUser(AccessAccountEmail);
_ds = new DirectoryService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = appName
});
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment