/// <summary> /// Exchange an authorization code for OAuth 2.0 credentials. /// </summary> /// <param name="authorizationCode">Authorization code to exchange for OAuth 2.0 credentials.</param> /// <param name="refreshToken"></param> /// <param name="callbackUrl"></param> /// <returns>OAuth 2.0 credentials.</returns> public static IAuthorizationState ExchangeCode([NotNull] String authorizationCode, string refreshToken, [NotNull] string callbackUrl) { if (authorizationCode == null) { throw new ArgumentNullException("authorizationCode"); } if (callbackUrl == null) { throw new ArgumentNullException("callbackUrl"); } var provider = new NativeApplicationClient( GoogleAuthenticationServer.Description, "647667148.apps.googleusercontent.com", "SHvBqFmGtXq5bTPqY242oNvB"); IAuthorizationState state = new AuthorizationState(); state.Callback = new Uri(callbackUrl); state.RefreshToken = refreshToken; try { state = provider.ProcessUserAuthorization(authorizationCode, state); provider.RequestUserAuthorization(); return(state); } catch (ProtocolException) { throw new Exception(null); } }
private static IAuthorizationState GetAuthentication(NativeApplicationClient client) { // You should use a more secure way of storing the key here as // .NET applications can be disassembled using a reflection tool. const string STORAGE = cacheFile; const string KEY = "y},drdzf11x9;87"; string scope = Google.Apis.Plus.v1.PlusService.Scopes.PlusMe.GetStringValue(); // Check if there is a cached refresh token available. IAuthorizationState state = AuthorizationMgr.GetCachedRefreshToken(STORAGE, KEY); if (state != null) { try { client.RefreshToken(state); return(state); // Yes - we are done. } catch (DotNetOpenAuth.Messaging.ProtocolException ex) { ex.ShowError(); } } // Retrieve the authorization from the user. state = AuthorizationMgr.RequestNativeAuthorization(client, scope); AuthorizationMgr.SetCachedRefreshToken(STORAGE, KEY, state); return(state); }
/// <summary> /// Return Analytics Service object /// </summary> /// <returns>Analytics Service object</returns> public static AnalyticsService GetAnalyticsService() { var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); provider.ClientIdentifier = Settings.ClientIdentifier; provider.ClientSecret = Settings.ClientSecret; if (string.IsNullOrWhiteSpace(provider.ClientIdentifier)) { throw new Exception("Client identifier not found"); } if (string.IsNullOrWhiteSpace(provider.ClientSecret)) { throw new Exception("Client secret not found"); } string refreshToken = Settings.RefreshToken; if (string.IsNullOrWhiteSpace(refreshToken)) { throw new Exception("Refresh token not found"); } var request = HttpContext.Current.Request; var authenticator = new OAuth2Authenticator <NativeApplicationClient>(provider, (arg) => { IAuthorizationState state = new AuthorizationState(new[] { "https://www.googleapis.com/auth/analytics.readonly" }); state.Callback = new Uri(string.Format("{0}://{1}{2}/GoogleAnalytics/Callback", request.Url.Scheme, request.Url.Host, request.Url.Port == 80 ? string.Empty : ":" + request.Url.Port)); state.RefreshToken = refreshToken; var result = arg.RefreshToken(state); return(state); }); return(new AnalyticsService(authenticator)); }
static void Main(string[] args) { String CLIENT_ID = "YOUR_CLIENT_ID"; String CLIENT_SECRET = "YOUR_CLIENT_SECRET"; // Register the authenticator and create the service var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET); var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthorization); var service = new DriveService(auth); File body = new File(); body.Title = "My document"; body.Description = "A test document"; body.MimeType = "text/plain"; byte[] byteArray = System.IO.File.ReadAllBytes("document.txt"); System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray); FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/plain"); request.Upload(); File file = request.ResponseBody; Console.WriteLine("File id: " + file.Id); }
private void button2_Click_1(object sender, EventArgs e) { try { NativeApplicationClient client = new NativeApplicationClient(GoogleAuthenticationServer.Description, this.clientID, this.clientSecret); OAuth2Authenticator <NativeApplicationClient> auth = new OAuth2Authenticator <NativeApplicationClient>(client, Authenticate); // Authenticated and ready for API calls... // EITHER Calendar API calls (tested): CalendarService cal = new CalendarService(auth); EventsResource.ListRequest listrequest = cal.Events.List(this.primaryCal); Google.Apis.Calendar.v3.Data.Events events = listrequest.Fetch(); // iterate the events and show them here. // OR Plus API calls (not tested) - copied from OP's code: var plus = new PlusService(auth); plus.Key = "BLAH"; // don't know what this line does. var me = plus.People.Get("me").Fetch(); Console.WriteLine(me.DisplayName); // OR some other API calls... } catch (Exception ex) { Console.WriteLine("Error while communicating with Google servers. Try again(?). The error was:\r\n" + ex.Message + "\r\n\r\nInner exception:\r\n" + ex.InnerException.Message); } }
public void Authentication(Ctx ctx) { var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); provider.ClientIdentifier = ClientCredentials.ClientID; provider.ClientSecret = ClientCredentials.ClientSecret; // Create the service. This will automatically call the authenticator. if (isTask) { var service = new TasksService(new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthentication)); Google.Apis.Tasks.v1.TasklistsResource.ListRequest clrq = service.Tasklists.List(); clrq.MaxResults = "1000"; TaskLists taskslist = clrq.Fetch(); FetchingTasks(service, taskslist, ctx); } else { var service = new CalendarService(new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthentication)); Google.Apis.Calendar.v3.CalendarListResource.ListRequest clrq = service.CalendarList.List(); var result = clrq.Fetch(); FetchingCalendar(result, service, ctx); } }
public static void Main(string[] args) { // Register an authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); provider.ClientIdentifier = clientId; provider.ClientSecret = clientSecret; // Initiate an OAuth 2.0 flow to get an access token var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthorization); // Create the service. var service = new BigqueryService(auth); JobsResource j = service.Jobs; QueryRequest qr = new QueryRequest(); qr.Query = query; QueryResponse response = j.Query(qr, projectId).Fetch(); foreach (TableRow row in response.Rows) { List <string> list = new List <string>(); foreach (TableRow.FData field in row.F) { list.Add(field.V); } Console.WriteLine(String.Join("\t", list)); } Console.WriteLine("\nPress enter to exit"); Console.ReadLine(); }
public static void Main(string[] args) { // Display the header and initialize the sample. CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("Tasks API: E-Tag collision"); // Register the authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); FullClientCredentials credentials = PromptingClientCredentials.EnsureFullClientCredentials(); provider.ClientIdentifier = credentials.ClientId; provider.ClientSecret = credentials.ClientSecret; var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthentication); // Create the service. var service = new TasksService(auth); // Run the sample code. RunSample(service, true, ETagAction.Ignore); RunSample(service, true, ETagAction.IfMatch); RunSample(service, true, ETagAction.IfNoneMatch); RunSample(service, false, ETagAction.Ignore); RunSample(service, false, ETagAction.IfMatch); RunSample(service, false, ETagAction.IfNoneMatch); CommandLine.PressAnyKeyToExit(); }
public static IAuthorizationState GetAuthorization(NativeApplicationClient Client) { try { const string KEY = "z},drdzf11x9;87"; string myScope = CalendarService.Scopes.Calendar.GetStringValue(); // Check if there is a cached refresh token available. IAuthorizationState myState = AuthorizationMgr.GetCachedRefreshToken(KEY); if (myState != null) { try { Client.RefreshToken(myState); return(myState); // Yes - we are done. } catch (DotNetOpenAuth.Messaging.ProtocolException ex) { //ErrorDump.AddError(System.IntPtr.Zero, "GAuth.cs", "GetAuthorization", ex, "Using existing refresh token failed"); } } // If we get here, there is no stored token. Retrieve the authorization from the user. myState = AuthorizationMgr.RequestNativeAuthorization(Client, myScope); AuthorizationMgr.SetCachedRefreshToken(KEY, myState); return(myState); } catch (Exception ex) { //ErrorDump.AddError(System.IntPtr.Zero, "GAuth.cs", "GetAuthorization", ex); return(null); } }
public static void Main(string[] args) { // Display the header and initialize the sample. CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("Tasks API"); // Register the authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); FullClientCredentials credentials = PromptingClientCredentials.EnsureFullClientCredentials(); provider.ClientIdentifier = credentials.ClientId; provider.ClientSecret = credentials.ClientSecret; var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthorization); // Create the service. var service = new TasksService(auth); // Execute request: Create sample list. if (!ListExists(service, SampleListName) && CommandLine.RequestUserChoice("Do you want to create a sample list?")) { CreateSampleTasklist(service); } CommandLine.WriteLine(); // Execute request: List task-lists. ListTaskLists(service); CommandLine.PressAnyKeyToExit(); }
string GetAuthorizationCodeFromUser(NativeApplicationClient arg, IAuthorizationState state) { ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe", arg.RequestUserAuthorization(state).ToString()); Process.Start(startInfo); Console.WriteLine("Please login to the web page that has opened and enter the provided authorization code into the console: "); return Console.ReadLine(); }
static void Main(string[] args) { // Display the header and initialize the sample. CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("AdSense Management API Command Line Sample"); // Register the authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); var credentials = PromptingClientCredentials.EnsureFullClientCredentials(); provider.ClientIdentifier = credentials.ClientId; provider.ClientSecret = credentials.ClientSecret; var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthentication); // Create the service. var service = new AdsenseService(auth); var accounts = GetAllAccounts.Run(service, MaxListPageSize); if (accounts.Items != null && accounts.Items.Count > 0) { // Get an example account ID, so we can run the following samples. var exampleAccountId = accounts.Items[0].Id; GetAccountTree.Run(service, exampleAccountId); GetAllAdClientsForAccount.Run(service, exampleAccountId, MaxListPageSize); } var adClients = GetAllAdClients.run(service, MaxListPageSize); if (adClients.Items != null && adClients.Items.Count > 0) { // Get an ad client ID, so we can run the rest of the samples. var exampleAdClientId = adClients.Items[0].Id; var adUnits = GetAllAdUnits.Run(service, exampleAdClientId, MaxListPageSize); if (adUnits.Items != null && adUnits.Items.Count > 0) { // Get an example ad unit ID, so we can run the following sample. var exampleAdUnitId = adUnits.Items[0].Id; GetAllCustomChannelsForAdUnit.Run(service, exampleAdClientId, exampleAdUnitId, MaxListPageSize); } var customChannels = GetAllCustomChannels.Run(service, exampleAdClientId, MaxListPageSize); if (customChannels.Items != null && customChannels.Items.Count > 0) { // Get an example custom channel ID, so we can run the following sample. var exampleCustomChannelId = customChannels.Items[0].Id; GetAllAdUnitsForCustomChannel.Run(service, exampleAdClientId, exampleCustomChannelId, MaxListPageSize); } GetAllUrlChannels.Run(service, exampleAdClientId, MaxListPageSize); GenerateReport.Run(service, exampleAdClientId); GenerateReportWithPaging.Run(service, exampleAdClientId, MaxReportPageSize); } CommandLine.PressAnyKeyToExit(); }
public void ConstructTest() { var client = new NativeApplicationClient(new Uri("http://example.com")); var auth = new OAuth2Authenticator <NativeApplicationClient>(client, (clt) => new AuthorizationState()); Assert.IsNull(auth.State); }
public void CheckForValidAccessTokenTest() { int accessTokenCounter = 1; var state = new AuthorizationState(); var client = new NativeApplicationClient(new Uri("http://example.com")); var auth = new OAuth2Authenticator <NativeApplicationClient>( client, (clt) => { // Load a "cached" access token. state.AccessToken = "token" + (accessTokenCounter++); return(state); }); // Check that the initial state is null. Assert.IsNull(auth.State); // Check that the state was set when .LoadAccessToken() is called. auth.LoadAccessToken(); Assert.AreEqual(state, auth.State); Assert.AreEqual("token1", auth.State.AccessToken); // Check that it wont be set again. auth.LoadAccessToken(); Assert.AreEqual("token1", auth.State.AccessToken); // Check that it is set if our state gets invalid. state.AccessToken = null; auth.LoadAccessToken(); Assert.AreEqual("token2", auth.State.AccessToken); }
private IAuthorizationState GetAuthorization(NativeApplicationClient arg) { // Get the auth URL: _state = new AuthorizationState(new[] { DriveService.Scopes.Drive.GetStringValue() }); _state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl); Uri authUri = arg.RequestUserAuthorization(_state); //Show Login UI. It's tip for user var dlg = new AuthDlg(StorageType.GDrive); dlg.Top = 0; dlg.Show(); // Request authorization from the user (by opening a browser window): //Process.Start(authUri.ToString()); _webViewCallback(authUri.ToString()); dlg.Close(); //close non-modal stub dialog //open another, modal dialog to block execution until user clicks OK dlg = new AuthDlg(StorageType.GDrive) { Top = 0 }; dlg.ShowDialog(); // Retrieve the access token by using the authorization code: return(arg.ProcessUserAuthorization(dlg.AuthCode, _state)); }
public static void Main(string[] args) { // Display the header and initialize the sample. CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("Tasks API"); // Register the authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description) { ClientIdentifier = "<client_id>", ClientSecret = "<client_secret>" }; var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthorization); // Create the service. var service = new TasksService(new BaseClientService.Initializer() { Authenticator = auth, ApplicationName = "Tasks API Sample", }); TaskLists results = service.Tasklists.List().Fetch(); Console.WriteLine("Lists:"); foreach (TaskList list in results.Items) { Console.WriteLine("- " + list.Title); } Console.ReadKey(); }
private IAuthorizationState getAuthorisation(NativeApplicationClient client) { IAuthorizationState state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() }); state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl); string refreshToken = LoadRefreshToken(); if (!String.IsNullOrWhiteSpace(refreshToken)) { state.RefreshToken = refreshToken; if (client.RefreshToken(state)) { return(state); } } if (!authRefreshOnly && authFunction != null) { Uri authUri = client.RequestUserAuthorization(state); string authResult = authFunction(authUri); var result = client.ProcessUserAuthorization(authResult, state); StoreRefreshToken(state); return(result); } else { return(null); } }
/// <summary> /// Method to get the authorization from the user to access their Google Drive from the application /// </summary> /// <param name="client"></param> /// <returns></returns> public static IAuthorizationState GetAuthorization(NativeApplicationClient client) { // You should use a more secure way of storing the key here as // .NET applications can be disassembled using a reflection tool. const string STORAGE = "gdrive_uploader"; const string KEY = "z},drdzf11x9;87"; string scope = DriveService.Scopes.Drive.GetStringValue(); // Check if there is a cached refresh token available. IAuthorizationState state = AuthorizationMgr.GetCachedRefreshToken(STORAGE, KEY); if (state != null) { try { client.RefreshToken(state); return(state); // Yes - we are done. } catch (DotNetOpenAuth.Messaging.ProtocolException ex) { Debug.WriteLine("Using existing refresh token failed: " + ex.Message); } } // If we get here, there is no stored token. Retrieve the authorization from the user. state = AuthorizationMgr.RequestNativeAuthorization(client, scope); AuthorizationMgr.SetCachedRefreshToken(STORAGE, KEY, state); return(state); }
public void Main(string CLIENT_ID, string CLIENT_SECRET) { // Register the authenticator and create the service var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET); var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthorization); var service = new DriveService(new BaseClientService.Initializer() { Authenticator = auth }); File body = new File(); body.Title = "My document.txt"; body.Description = "A test document"; body.MimeType = "text/plain"; byte[] byteArray = Encoding.UTF8.GetBytes("Hello world!!"); System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray); FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/plain"); request.Upload(); if (request.ResponseBody == null) { return; } var id = request.ResponseBody.Id; Console.WriteLine("File id: " + id); Console.WriteLine("Press Enter to end this process."); //Console.ReadLine(); }
public static void Main(string[] args) { // Display the header and initialize the sample. CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("Tasks API"); // Register the authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); FullClientCredentials credentials = PromptingClientCredentials.EnsureFullClientCredentials(); provider.ClientIdentifier = credentials.ClientId; provider.ClientSecret = credentials.ClientSecret; var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthorization); // Create the service. var service = new TasksService(auth); TaskLists results = service.Tasklists.List().Fetch(); CommandLine.WriteLine(" ^1Lists:"); foreach (TaskList list in results.Items) { CommandLine.WriteLine(" ^2" + list.Title); } CommandLine.PressAnyKeyToExit(); }
private static IAuthorizationState GetAuthentication(NativeApplicationClient client) { // You should use a more secure way of storing the key here as // .NET applications can be disassembled using a reflection tool. const string STORAGE = "google.samples.dotnet.siteverification"; const string KEY = "y},drdzf11x9;87"; // Check if there is a cached refresh token available. IAuthorizationState state = AuthorizationMgr.GetCachedRefreshToken(STORAGE, KEY); if (state != null) { try { client.RefreshToken(state); return(state); // Yes - we are done. } catch (DotNetOpenAuth.Messaging.ProtocolException ex) { CommandLine.WriteError("Using existing refresh token failed: " + ex.Message); } } // Retrieve the authorization from the user. state = AuthorizationMgr.RequestNativeAuthorization(client, Scope); AuthorizationMgr.SetCachedRefreshToken(STORAGE, KEY, state); return(state); }
public GoogleCalendar() { //UserCredential credential; //using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read)) //{ // //var clientSecrets = GoogleClientSecrets.Load(stream).Secrets; // credential = GoogleWebAuthorizationBroker.AuthorizeAsync( // stream, // new[] { CalendarService.Scope.Calendar }, // "user", CancellationToken.None, new FileDataStore("Calendar.ListMyLibrary")).Result; // service = new CalendarService(new BaseClientService.Initializer() // { // HttpClientInitializer = credential, // ApplicationName = "Outlook Google Sync" , // }); // //credential = authorizeAsync.Result; //} var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); provider.ClientIdentifier = "646754649922-g2p0157e4q3d5qv25ia3ur09vrc455k6.apps.googleusercontent.com"; provider.ClientSecret = "ZyPfCdrOFb6y-VWrdVZ65_8M"; service = new CalendarService(new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthentication)); service.Key = "AIzaSyCg7QtvUT6V3Hh3ZG7M5KfDiFScRkaYix0"; }
private static IAuthenticator CreateAuthenticator() { var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); provider.ClientIdentifier = ClientCredentials.ClientID; provider.ClientSecret = ClientCredentials.ClientSecret; return(new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthentication)); }
/// <summary> /// create authenticator object gor google drive service /// </summary> /// <returns></returns> private static IAuthenticator createAuthenticator() { var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); provider.ClientIdentifier = "349699183942-1fo1k1b6c464e95cqrjfkn9sgeekklog.apps.googleusercontent.com"; provider.ClientSecret = "8jJRhXy3oeT5uC8ji2qKxct5"; return(new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthorization)); }
public static NativeApplicationClient GetProvider() { var provider = new NativeApplicationClient( GoogleAuthenticationServer.Description, Common.ClientID, Common.ClientSecret); return(provider); }
private static void Main(string[] args) { UtilArguments utilArguments = new UtilArguments(args); UtilAuthorization authorization = new UtilAuthorization(); File file = new File(); string clientID = ConfigurationManager.AppSettings["clientID"]; string clientSecret = ConfigurationManager.AppSettings["clientSecret"]; var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, clientID, clientSecret); var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, authorization.GetAuthorization); var service = new DriveService(auth); if (utilArguments["pub"] != null) { IServiceUploadDocument uploadDocument = new ServiceUploadDocument(new File()); file = uploadDocument.UploadDocument(service, @"www2net"); if (utilArguments["type"] != null) { file = uploadDocument.UploadDocument(service, @"www2net"); } } if (utilArguments["mkdir"] != null) { IServiceCreatePublicFolder serviceCreatePublicFolder = new ServiceCreatePublicFolder(new File(), new Permission()); string mkdir = utilArguments["mkdir"]; Console.WriteLine("Creating Public Shared Folder" + mkdir); file = serviceCreatePublicFolder.Mkdir(service, mkdir); IServiceUrlShortner serviceUrlShortner = new ServiceUrlShortner(new UrlshortenerService()); string uri = @"URL=" + serviceUrlShortner.Shorten("https://googledrive.com/host/" + file.Id); Console.WriteLine("Writting URL Shortcut to Desktop"); Console.WriteLine(uri); string path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); using (System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(path + "\\" + mkdir + ".url")) { streamWriter.WriteLine("[InternetShortcut]"); streamWriter.WriteLine(uri); streamWriter.Flush(); } } Console.WriteLine("File id: " + file.Id); Console.WriteLine("Press Enter to end this process."); Console.ReadLine(); }
/// <summary> /// 初始化NativeApplicationClient provider /// </summary> private static void InitProvider() { if (provider == null) { provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); } provider.ClientIdentifier = CLIENTIDENTIFIER; provider.ClientSecret = CLIENTSECRET; }
/// <summary> /// Returns an OAuth 2.0 provider for the authorization flow. /// </summary> /// <returns>OAuth 2.0 provider.</returns> private NativeApplicationClient GetProvider() { var provider = new NativeApplicationClient( GoogleAuthenticationServer.Description, Config.CLIENT_ID, Config.CLIENT_SECRET); return(provider); }
public GoogleCalendar() { var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); provider.ClientIdentifier = "1048601141806-9ek0gtv3bjonb7cifqaedf8gh3e8sive.apps.googleusercontent.com"; provider.ClientSecret = "F6uRAziIV-EdFsb6oRjTAY45"; service = new CalendarService(new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthentication)); service.Key = "AIzaSyChF6Uf0z9PthPzZ1Qy2lHZ_OrXW6oMUBk"; }
/// <summary> /// OAuth验证方法 /// </summary> /// <param name="arg"></param> /// <returns></returns> private static IAuthorizationState GetAuthorization(NativeApplicationClient arg) { IAuthorizationState state = new AuthorizationState(new[] { AUTHURI }); state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl); state.AccessToken = ACCESSTOKEN; Uri authUri = arg.RequestUserAuthorization(state); return(arg.ProcessUserAuthorization(authcode)); }