gpt4 book ai didi

java - 发生错误时读取谷歌电子表格

转载 作者:行者123 更新时间:2023-12-01 06:20:55 25 4
gpt4 key购买 nike

当我的程序运行到 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();
}

}

最佳答案

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

关于java - 发生错误时读取谷歌电子表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6434672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com