C# 使用api v3在Google日历中创建事件
我在c#net中尝试了谷歌的这个示例,但它对我不起作用。任何人都有谷歌日历api v3的任何示例 它向我显示了错误,因为当前内容中不存在AuthenticatorFactory 我使用谷歌提供的dllC# 使用api v3在Google日历中创建事件,c#,google-calendar-api,sample,C#,Google Calendar Api,Sample,我在c#net中尝试了谷歌的这个示例,但它对我不起作用。任何人都有谷歌日历api v3的任何示例 它向我显示了错误,因为当前内容中不存在AuthenticatorFactory 我使用谷歌提供的dll using System; using System.Diagnostics; using DotNetOpenAuth.OAuth2; using Google.Apis.Authentication; using Google.Apis.Authentication.OAuth2; using
using System;
using System.Diagnostics;
using DotNetOpenAuth.OAuth2;
using Google.Apis.Authentication;
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using Google.Apis.Calendar.v3;
using Google.Apis.Calendar.v3.Data;
using Google.Apis.Util;
namespace Sample.Console
{
class Program
{
static void Main(string[] args)
{
// Register the authenticator. The Client ID and secret have to be copied from the API Access
// tab on the Google APIs Console.
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
provider.ClientIdentifier = "YOUR_CLIENT_ID";
provider.ClientSecret = "YOUR_CLIENT_SECRET";
AuthenticatorFactory.GetInstance().RegisterAuthenticator(
() => new OAuth2Authenticator(provider, GetAuthentication));
// Create the service. This will automatically call the previously registered authenticator.
var service = new CalendarService();
}
private static IAuthorizationState GetAuthentication(NativeApplicationClient arg)
{
// Get the auth URL:
IAuthorizationState state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() });
state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri = arg.RequestUserAuthorization(state);
// Request authorization from the user (by opening a browser window):
Process.Start(authUri.ToString());
Console.Write(" Authorization Code: ");
string authCode = Console.ReadLine();
Console.WriteLine();
// Retrieve the access token by using the authorization code:
return arg.ProcessUserAuthorization(authCode, state);
}
}
}
google没有使用Auth Factory use OAuth2 authenticator对象,而是很好地记录了这一更改…只是用AuthenticatorFactory.GetInstance()删除了代码。。。。并替换为这行代码。其他一切都应该保持不变
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
var auth=新的OAuth2Authenticator(提供者,GetAuthorization);