我正在尝试编写一个本机应用程序来访问用户的谷歌日历。我正在尝试使用谷歌提供的示例来获取身份验证,但它似乎从未触发身份验证功能
private void Window_Initialized(object sender, EventArgs e)
{
var provider = new NativeApplicationClient(
GoogleAuthenticationServer.Description);
provider.ClientIdentifier = "<My Client Id here>";
provider.ClientSecret = "<My Client Secret here";
var auth = new OAuth2Authenticator<NativeApplicationClient>(
provider, (p) => GetAuthorization(provider));
CalendarService service = new CalendarService();
CalendarsResource.GetRequest cr = service.Calendars.Get("{primary}");
if (cr.CalendarId != null)
{
Console.WriteLine("Fetching calendar");
//Google.Apis.Calendar.v3.Data.Calendar c =
service.Calendars.Get("{primary}").Fetch();
}
else
{
Console.WriteLine("Service not found");
}
}
这是我用于身份验证的代码。我从来没有看到控制台写行被发布。
private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
{
Console.WriteLine("Authorization Requested");
IAuthorizationState state = new AuthorizationState(
new[] { CalendarService.Scopes.Calendar.GetStringValue() });
state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri = arg.RequestUserAuthorization(state);
Process.Start(authUri.ToString());
// Request authorization from the user and get the code
string authCode = Console.ReadLine();
// Retrieve the access token by using the authorization code:
return arg.ProcessUserAuthorization(authCode, state);
}
有没有更好的教程可用或者我做错了什么?