gpt4 book ai didi

C# 谷歌登录

转载 作者:行者123 更新时间:2023-11-30 16:27:46 25 4
gpt4 key购买 nike

我正在维护一些我想添加聊天功能的代码。我已经有一个客户端/服务器/数据库设置,但我想做的是使用谷歌帐户登录,而不是人们必须创建新帐户等。谁能指出我正确的方向?我已经下载了这个 http://code.google.com/p/google-gdata/我走在正确的轨道上吗?

还要澄清一下,这不是一个 asp 项目,它是一个桌面项目。

最佳答案

经过大量修补,我想出了这个解决方案。它看起来很简单,但我找不到任何合适的文档。我相信人们会发现这非常有帮助。只需从 http://code.google.com/p/google-gdata/ 获取 Google API并添加 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;
}

这不是我使用的确切代码,我只是提取了它的骨架并以更通用的方式重写了它。

关于C# 谷歌登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7577654/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com