C#谷歌登录
我正在维护一些我想添加聊天功能的代码。我已经有了一个客户机/服务器/数据库设置,但我想做的是使用谷歌帐户登录,而不是人们必须创建新的帐户等。 谁能给我指一下正确的方向吗? 我已经下载了这个,我走对了吗C#谷歌登录,c#,login,C#,Login,我正在维护一些我想添加聊天功能的代码。我已经有了一个客户机/服务器/数据库设置,但我想做的是使用谷歌帐户登录,而不是人们必须创建新的帐户等。 谁能给我指一下正确的方向吗? 我已经下载了这个,我走对了吗 同样要澄清的是,这不是一个asp项目,而是一个桌面项目。对于桌面应用程序,请查看Google在上的文档。您的应用程序(显然)需要启动浏览器的功能,这样用户就可以通过Google进行身份验证。经过大量修改,我终于想出了这个解决方案。它看起来很简单,但我却找不到任何合适的文档。我相信人们会觉得这非常有
同样要澄清的是,这不是一个asp项目,而是一个桌面项目。对于桌面应用程序,请查看Google在上的文档。您的应用程序(显然)需要启动浏览器的功能,这样用户就可以通过Google进行身份验证。经过大量修改,我终于想出了这个解决方案。它看起来很简单,但我却找不到任何合适的文档。我相信人们会觉得这非常有帮助。 只需从 并添加Google.GData.Client.dll作为参考(位于redist文件夹下)
这不是我使用的确切代码,我只是把它的框架拉出来,用一种更通用的方式重写了它。实际上它不需要启动浏览器。
using Google.GData.Client;
public bool Google_Login(string email,string password, string captcha,string captchatoken)
{
String AppName = "MyCompany-MyApp-1.0.0.0";
Service s = new Service("code", AppName); //Can use any service, I just happened to want to use GoogleCode
s.setUserCredentials(email, password);
if(captcha != null && captchatoken != null) //If we already tried to log in, but we needed to captcha
{
if(!String.IsNullOrWhiteSpace(captcha) || !String.IsNullOrWhiteSpace(captchatoken))
{
s.Credentials.CaptchaToken = captchatoken;
s.Credentials.CaptchaAnswer = captcha;
}
}
try
{
string ret = s.QueryClientLoginToken();
//If we end up here, then the credentials are correct.
}
catch(Google.GData.Client.CaptchaRequiredException ce)
{
//ce.Url is the full url of the Captcha image
//If you would rather handle the captcha from
//a webpage, you can make your user go here "https://www.google.com/accounts/DisplayUnlockCaptcha"
//TODO Some way to display the captcha image and get user feedback
//we'll just say you did that and returned a string named retCaptcha
return Google_Login(email,password, retCaptcha,ce.Token);
}
catch(Google.GData.Client.AuthenticationException re)
{
//re.Message is the specific message google sends back about the login attempt.
return false;
}
catch(WebException e)
{
//Haven't ended up here yet, but I'm sure it's possible.
return false;
}
//If we somehow end up here
return false;
}