简体   繁体   English

来自网站的Google API身份验证

[英]Google API Authentication from Web site

I need to access a Google Spreadsheet from my web application. 我需要从Web应用程序访问Google Spreadsheet。 This is a membership application that writes member info to the google spreadsheet. 这是一个将会员信息写入Google电子表格的会员应用程序。 When I run the code locally, the code below works. 当我在本地运行代码时,以下代码有效。

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

However, when I am running the web application on the server, the authentication fails. 但是,当我在服务器上运行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)

I also got this email from google: 我还从Google收到了这封电子邮件:

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:

I know the credentials are correct because they work when testing locally. 我知道凭据是正确的,因为它们在本地测试时会起作用。

I see a lot of mention of OAuth for authentication. 我看到很多关于身份验证的OAuth提及。 The problem is I don't want to use the user's authentication. 问题是我不想使用用户的身份验证。 Only my web app should be allowed to write to the spreadsheet, using the credentials I've supplied. 使用我提供的凭据,仅允许我的Web应用程序写入电子表格。

I went to the following URL, clicked on the button, and everything works now. 我转到以下URL,单击按钮,一切正常。 Really strange that this step is required. 真奇怪,这是必需的步骤。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM