【问题标题】:read google spreadsheet when an error occurs发生错误时阅读谷歌电子表格
【发布时间】:2011-06-22 03:45:43
【问题描述】:

当我的程序运行到 service.getFeed(metafeedUrl, SpreadsheetFeed.class)

java.net.ConnectException: Connection timed out: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(Unknown Source)
    at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source)
    at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:503)
    at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
    at com.google.gdata.client.Service.getFeed(Service.java:1135)
    at com.google.gdata.client.Service.getFeed(Service.java:998)
    at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631)
    at com.google.gdata.client.Service.getFeed(Service.java:1017)
    at GdataTest.main(GdataTest.java:55)

我不知道如何解决这个问题。 请帮帮我,我是中国人, 所以我的英语不好,希望你明白我的意思。

这是我的代码:

    try {
        final URL url = new URL(
                "https://www.google.com/accounts/ClientLogin");
        final URLConnection urlConn = url.openConnection();
        urlConn.setDoInput(true);
        urlConn.setDoOutput(true);
        urlConn.setUseCaches(false);
        urlConn.setRequestProperty("Content-type",
                "application/x-www-form-urlencoded");

        final DataOutputStream cgiInput = new DataOutputStream(
                urlConn.getOutputStream());

        String content = null;
        content = "accountType=" + "HOSTED" + "&Email=" + email
                + "&Passwd=" + password + "&service=" + "wise" + "&source="
                + applicationName;
        cgiInput.writeBytes(content);
        cgiInput.flush();
        cgiInput.close();

        if (urlConn instanceof HttpURLConnection) {
            final boolean status = ((HttpURLConnection) urlConn)
                    .getResponseCode() == 200;
            if (status) {
                System.out.println("i'm in");
                SpreadsheetService service = new 
                        SpreadsheetService(applicationName);
                URL metafeedUrl = new 
                        URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
                SpreadsheetFeed feed = service.getFeed(metafeedUrl, SpreadsheetFeed.class);

                List<SpreadsheetEntry> spreadsheets = feed.getEntries();
                for (int i = 0; i < spreadsheets.size(); i++) {
                  SpreadsheetEntry entry = spreadsheets.get(i);
                  System.out.println("\t" + entry.getTitle().getPlainText());
                }
            }
        }

    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ServiceException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

【问题讨论】:

  • 错误提示代码的第 55 行,哪一行是第 55 行?
  • SpreadsheetFeed feed = service.getFeed(metafeedUrl, SpreadsheetFeed.class);当我 getFeed 时,我得到了错误

标签: java google-sheets


【解决方案1】:

您是否使用代理?你可能需要设置java代理,这里的说明http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html

【讨论】:

  • 但是我已经设置好了,我可以通过我的浏览器查看谷歌电子表格(使用代理)。
猜你喜欢
  • 1970-01-01
  • 2011-03-31
  • 1970-01-01
  • 2017-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-16
相关资源
最近更新 更多