谷歌电子表格API(Java)

谷歌电子表格API(Java),java,google-sheets,gdata,Java,Google Sheets,Gdata,我想用一个简单的java程序计算的数值来更新电子表格。 它不是Android应用程序或其他任何东西,只是普通的java 问题是我退出了这个程序,说这个帐户无效。 但是提供的凭证是100%有效的-我从eclipse中复制了它们并将它们粘贴到gmail登录表单中-它们可以工作 api教程中的基本类: import com.google.gdata.client.spreadsheet.*; import com.google.gdata.data.spreadsheet.*; import com.

我想用一个简单的java程序计算的数值来更新电子表格。 它不是Android应用程序或其他任何东西,只是普通的java

问题是我退出了这个程序,说这个帐户无效。 但是提供的凭证是100%有效的-我从eclipse中复制了它们并将它们粘贴到gmail登录表单中-它们可以工作

api教程中的基本类:

import com.google.gdata.client.spreadsheet.*;
import com.google.gdata.data.spreadsheet.*;
import com.google.gdata.util.*;

import java.io.IOException;
import java.net.*;

public class MySpreadsheetIntegration {
  public static void main(String[] args)
      throws AuthenticationException, MalformedURLException, IOException, ServiceException {

    String USERNAME = "abc@gmail.com";
    String PASSWORD = "123";

    SpreadsheetService service =
        new SpreadsheetService("MySpreadsheetIntegration-v1");
    service.setUserCredentials(USERNAME, PASSWORD);

    // TODO: See other portions of this guide for code to put here...
  }
}
堆栈跟踪:

Exception in thread "main" com.google.gdata.client.GoogleService$InvalidCredentialsException: Invalid credentials
at com.google.gdata.client.GoogleAuthTokenFactory.getAuthException(GoogleAuthTokenFactory.java:660)
at com.google.gdata.client.GoogleAuthTokenFactory.getAuthToken(GoogleAuthTokenFactory.java:560)
at com.google.gdata.client.GoogleAuthTokenFactory.setUserCredentials(GoogleAuthTokenFactory.java:397)
at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:364)
at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:319)
at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:303)
at MySpreadsheetIntegration.main(MySpreadsheetIntegration.java:17)

我想知道,使用不带android sdk之类的api是否可能实现这一点?

谷歌电子表格api使用OAuth作为其服务的授权协议(在本例中为api)。阅读上的部分,了解应用程序如何获得授权和访问API

也请考虑谷歌的警告:

警告:强烈反对将ClientLogin用作授权机制。在使用此机制之前,请彻底 考虑使用存储的刷新令牌或OAuth1.0a的OAuth2 使用存储的访问令牌


使用Oauth不是强制性的。但是,为了使没有Oauth的身份验证能够工作,您必须在您的google帐户安全设置中启用lessSecureApps用于上述尝试登录的帐户


要打开lessSecureApps,请转到

谢谢,我现在的问题是没有java代码段,只是。如果仔细阅读,代码右上角有一个标签,上面写着java。所以你可以在Java和.NET之间切换。很抱歉,关于“执行OAuth 2.0”这一主题,我是瞎了眼,或者Java没有。好吧,代码很清楚,假设你可以将缺少更好的word的代码粘贴到Java中,并修复导入和各种编译错误。对我来说,重构代码并不是那么容易。。。OAuth2Parameters-类变为com.google.gdata.client.authn.oauth.OAuthParameters??设置id、secret和uri的正确属性是什么?OAuthUtil没有任何静态方法。。。我真的不明白为什么他们不给我们一个java代码片段——毕竟所有希望使用GDataAPI的android应用程序都需要它。。