Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为DotNetOpenAuth编写VB或C#GUI客户端?_C#_Vb.net_Winforms_User Interface_Dotnetopenauth - Fatal编程技术网

如何为DotNetOpenAuth编写VB或C#GUI客户端?

如何为DotNetOpenAuth编写VB或C#GUI客户端?,c#,vb.net,winforms,user-interface,dotnetopenauth,C#,Vb.net,Winforms,User Interface,Dotnetopenauth,我正在学习如何使用Google日历API,这反过来又要求我学习如何使用DotNetOpenAuth访问Google帐户。我使提供的示例正常工作,并在控制台程序中编写了工作代码来访问和操作日历 我现在想写一个Windows窗体应用程序(用C#或VB)来做同样的事情。我无法使OAuth2进程在GUI应用程序中工作。它编译并运行,但不起作用。根据我到目前为止看到的情况,我得出结论,GetAuthorization()函数没有被调用 我试着从点击按钮、构造函数和表单加载器方法开始这个过程。我试过C#和V

我正在学习如何使用Google日历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);
}
publicGooglecal()
{
初始化组件();
var provider=新的本地应用程序客户端(
GoogleAuthenticationServer.Description);
provider.ClientIdentifier=“xxxxx.apps.googleusercontent.com”;
provider.ClientSecret=“yyyyy”;
var auth=新的OAuth2Authenticator(
提供商,获取授权);
}
私有IAAuthorizationState GetAuthorization(NativeApplication客户端参数)
{
//获取身份验证URL:
IAAuthorizationState=新授权状态(新[]{
CalendarService.Scopes.Calendar.GetStringValue()});
state.Callback=新Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri=arg.RequestUserAuthorization(状态);
//请求用户授权(通过打开浏览器窗口):
Process.Start(authUri.ToString());
authCodeText=Microsoft.VisualBasic.Interaction.InputBox(
“粘贴代码:”、“标题”、“”);
//使用授权代码检索访问令牌:
返回arg.ProcessUserAuthorization(authCodeText,状态);
}

我显然做错了什么,但我不知道是什么。有什么想法吗?

使用whelkaholism.blogspot上的教程,我可以做我想做的事情。我采用了一种稍微不同的方法(部分是为了使用较新的OAuth2)

我的C#表单程序代码如下

// Add references:
//      DotNetOpenAuth.dll
//      Google.Apis.dll
//      Google.Apis.Authentication.OAth2.dll
//      Newtonsoft.Json.Net35.dll
// plus, add references for whichever Google App(s) you want
//      Google.Apis.Calendar.v3.dll

// form contains at least the following:
//      button1: Button, start the authentication process
//      authCode: TextBox, to recive the auth code from Google
//      button2: Button, complete the authentication prop
//      textBox2: TextBox, multi-line, to display status message and output

// in addition to the libraries required for any forms program, use:
using System.Diagnostics;
using DotNetOpenAuth.OAuth2;
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;


// methods not related to authentication deleted for space

namespace GoogleCal
{
    public partial class GoogleCal : Form
    {
        private static String NL = Environment.NewLine;
        private static IAuthorizationState state;
        private static NativeApplicationClient provider;
        private static OAuth2Authenticator<NativeApplicationClient> auth;
        private static CalendarService calService;

        private void button1_Click(object sender, EventArgs e)
        {
            // clicked to initiate authentication process

            // provider and state are declared above as private static

            provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
            provider.ClientIdentifier = "<my id>.apps.googleusercontent.com";
            provider.ClientSecret = "<my secret>";

            // next line changes if you want to access something other than Calendar
            state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() });
            state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
            Uri authUri = provider.RequestUserAuthorization(state);

            Process.Start(authUri.ToString());
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // clicked after Google code is pasted into TextBox to complete authentication process

            // auth and calService are declared above as private static

            auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);

            // create the service object to use in other methods
            calService = new CalendarService(auth);

            textBox2.AppendText("Ready" + NL);
            textBox2.Update();
        }

        private IAuthorizationState GetAuthorization(NativeApplicationClient arg)
        {
            // state is declared above as private static
            // authCode is a TextBox on the form
            return arg.ProcessUserAuthorization(authCode.Text, state);
        }
    }
}
//添加引用:
//DotNetOpenAuth.dll
//Google.api.dll
//Google.api.Authentication.OAth2.dll
//Newtonsoft.Json.Net35.dll
//另外,为你想要的谷歌应用添加参考
//Google.api.Calendar.v3.dll
//表单至少包含以下内容:
//按钮1:按钮,启动身份验证过程
//authCode:TextBox,用于从Google接收验证代码
//按钮2:按钮,完成身份验证
//文本框2:文本框,多行,用于显示状态消息和输出
//除任何表单程序所需的库外,请使用:
使用系统诊断;
使用DotNetOpenAuth.OAuth2;
使用Google.api.Authentication.OAuth2;
使用Google.api.Authentication.OAuth2.DotNetOpenAuth;
使用Google.api.Calendar.v3;
使用Google.api.Calendar.v3.Data;
使用Google.api.Util;
//已删除与空间的身份验证无关的方法
名称空间谷歌
{
公共部分类GoogleCal:Form
{
私有静态字符串NL=Environment.NewLine;
私有静态IAuthorizationState状态;
私有静态本地应用程序客户端提供程序;
私有静态OAuth2Authenticator auth;
专用静态日历服务;
私有无效按钮1\u单击(对象发送者,事件参数e)
{
//单击以启动身份验证过程
//提供者和状态在上面声明为私有静态
provider=新的NativeApplicationClient(GoogleAuthenticationServer.Description);
provider.ClientIdentifier=“.apps.googleusercontent.com”;
provider.ClientSecret=“”;
//如果要访问日历以外的内容,则下一行将更改
state=newauthorizationstate(new[]{CalendarService.Scopes.Calendar.GetStringValue()});
state.Callback=新Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri=provider.RequestUserAuthorization(状态);
Process.Start(authUri.ToString());
}
私有无效按钮2\u单击(对象发送者,事件参数e)
{
//在谷歌代码粘贴到文本框后单击以完成身份验证过程
//auth和calService在上面声明为私有静态
auth=新的OAuth2Authenticator(提供者,GetAuthorization);
//创建要在其他方法中使用的服务对象
calService=新日历服务(auth);
textBox2.AppendText(“就绪”+NL);
textBox2.Update();
}
私有IAAuthorizationState GetAuthorization(NativeApplication客户端参数)
{
//状态在上面声明为私有静态
//authCode是表单上的文本框
返回arg.ProcessUserAuthorization(authCode.Text,状态);
}
}
}

这是一个类似的问题,但不是我想问的问题。(另一方面,它可能是我能得到的最接近的…)这里讨论的解决方案似乎只有.asp。我要找的东西是c#或仅vb。ASP是vb或c#你不是要找的东西。net只是vb6吗?或者winforms或wpf?没有足够的信息来获取您想要的内容。我正在尝试创建一个Windows窗体应用程序VS 2010。“Windows窗体应用程序(在C#或VB中)”-抱歉,我没有读到这篇文章