【发布时间】:2023-03-31 10:30:01
【问题描述】:
我正在学习如何使用 Google Calendar API,这反过来又要求我学习如何使用 DotNetOpenAuth 来访问 Google 帐户。我使提供的示例工作,并在控制台程序中编写了工作代码来访问和操作日历。
我现在想编写一个 Windows 窗体应用程序(在 C# 或 VB 中)来做同样的事情。我无法让 OAuth2 进程在 GUI 应用程序中工作。它编译并运行,但不起作用。根据我目前看到的情况,我得出的结论是没有调用 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);
}
我显然做错了什么,但我不知道是什么。有什么想法吗?
【问题讨论】:
-
这是一个类似的问题,但不是我要问的。 (另一方面,它可能尽可能接近......)那里讨论的解决方案似乎是.asp-only。我正在寻找只有 c# 或 vb 的东西。
-
ASP 是 vb 或 C# 你不是在寻找 .net 只是 vb6 的东西吗?或者可能是 winforms 或 wpf ?没有足够的信息来获取您要查找的内容
-
我正在尝试创建一个 Windows 窗体应用程序 VS 2010。
-
“Windows 窗体应用程序(在 C# 或 VB 中)” - 抱歉,我没有阅读此内容
标签: c# vb.net winforms user-interface dotnetopenauth