我正在维护一些我想要添加聊天功能的代码。我已经有一个客户端/服务器/数据库设置,但我想做的是使用谷歌帐户登录,而不是人们必须创建新的帐户等。有谁能给我指个方向吗?我已经下载了这个http://code.google.com/p/google-gdata/,我走对了吗?
只是为了澄清一下,这不是一个asp项目,它是一个桌面项目。
发布于 2011-09-29 22:35:49
经过多次修修补补,我终于想出了这个解决方案。它看起来很简单,但我找不到任何关于它的适当文档。我相信人们会发现这非常有帮助。只需从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;
}这不是我使用的确切代码,我只是把它的骨架拉出来,并以更通用的方式重写了它。
发布于 2011-09-28 10:26:52
对于桌面应用程序,可以查看谷歌在OAuth 1.0 for Installed Applications上的文档。您的应用程序(显然)将需要启动浏览器的功能,以便用户可以使用Google进行身份验证。
https://stackoverflow.com/questions/7577654
复制相似问题