我正在学习如何使用Google Calendar API,这需要我学习如何使用DotNetOpenAuth来访问Google帐户。我已经使提供的示例正常工作,并编写了控制台程序中的工作代码以访问和操作日历。
现在我想编写一个Windows窗体应用程序(使用C#或VB)来实现同样的功能。我无法在GUI应用程序中使OAuth2过程正常工作。它可以编译和运行,但并不起作用。根据我目前看到的,我得出结论GetAuthorization()函数没有被调用。
我尝试从按钮单击、构造函数和表单装载方法开始进程。我尝试了C#和VB两种语言。
我显然做错了什么,但我无法弄清楚是什么。有任何想法吗?
现在我想编写一个Windows窗体应用程序(使用C#或VB)来实现同样的功能。我无法在GUI应用程序中使OAuth2过程正常工作。它可以编译和运行,但并不起作用。根据我目前看到的,我得出结论GetAuthorization()函数没有被调用。
我尝试从按钮单击、构造函数和表单装载方法开始进程。我尝试了C#和VB两种语言。
public GoogleCal()
{
InitializeComponent();
var provider = new NativeApplicationClient(
GoogleAuthenticationServer.Description);
provider.ClientIdentifier = "xxxxx.apps.googleusercontent.com";
provider.ClientSecret = "yyyyy";
var auth = new OAuth2Authenticator<NativeApplicationClient>(
provider, GetAuthorization);
}
private IAuthorizationState GetAuthorization(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());
authCodeText = Microsoft.VisualBasic.Interaction.InputBox(
"Paste code:", "title", "");
// Retrieve the access token by using the authorization code:
return arg.ProcessUserAuthorization(authCodeText, state);
}
我显然做错了什么,但我无法弄清楚是什么。有任何想法吗?