来自网站的Google API身份验证

时间:2014-09-03 18:55:12

标签: c# authentication google-api

我需要从我的网络应用程序访问Google电子表格。这是一个会员申请,可将会员信息写入谷歌电子表格。 当我在本地运行代码时,下面的代码可以工作。

SpreadsheetsService service = new SpreadsheetsService(spreadsheetName);
service.setUserCredentials(USERNAME, PASSWORD);

但是,当我在服务器上运行Web应用程序时,身份验证失败。

Google.GData.Client.InvalidCredentialsException: Invalid credentials
at Google.GData.Client.Utilities.QueryClientLoginToken(GDataCredentials gc, String     serviceName, String applicationName, Boolean fUseKeepAlive, IWebProxy proxyServer, Uri clientLoginHandler)
at Google.GData.Client.GDataGAuthRequest.QueryAuthToken(GDataCredentials gc)
at Google.GData.Client.GDataGAuthRequest.EnsureCredentials()
at Google.GData.Client.GDataRequest.EnsureWebRequest()
at Google.GData.Client.GDataGAuthRequest.EnsureWebRequest()
at Google.GData.Client.GDataRequest.Execute()
at Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter)
at Google.GData.Client.GDataGAuthRequest.Execute()
at Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince, String etag, Int64& contentLength)
at Google.GData.Client.Service.Query(FeedQuery feedQuery)

我也收到了来自谷歌的这封电子邮件:

Hi xxxxxx, 

Someone recently used your password to try to sign in to your Google Account 
xxxx@gmail.com. This person was using an application such as an email client 
or mobile device. 

We prevented the sign-in attempt in case this was a hijacker trying to access 
your account. Please review the details of the sign-in attempt:

我知道凭据是正确的,因为它们在本地测试时起作用。

我看到很多提及OAuth的身份验证。问题是我不想使用用户的身份验证。只允许我的网络应用程序使用我提供的凭据写入电子表格。

1 个答案:

答案 0 :(得分:0)

我转到了以下网址,点击了按钮,现在一切正常。非常奇怪,这一步是必需的。

https://accounts.google.com/b/0/DisplayUnlockCaptcha