public void Authenticate() { //execute off of the main ui thread so that the auth window can be shown Task.Run(() => { // Set an output path for the saved authorisation token string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); credPath = Path.Combine(credPath, String.Format(".credentials{0}{1}", Path.DirectorySeparatorChar, ApplicationName.ToLower())); UserCredential credential = null; /*** * Replace client_id and the client_secret(and any other values) from the client_secret.json file * * You can also create a new client_secret.json file from the Google Develeopers console * * https://console.developers.google.com * */ using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read)) { credential = MacGoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; } // Create Drive API service. var GoogleDriveService = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); }); }