使用facebook api的java桌面应用程序(java.net.unknownhost异常)

iaqfqrcu  于 2021-07-09  发布在  Java
关注(0)|答案(2)|浏览(360)

我正在尝试用google提供的facebook api构建一个java桌面应用程序。我有几个问题:
1) 我必须使用套接字编程吗(因为我是一个新手,我没有:/)
2) 当我尝试创建一个auth\ u令牌时,它在facebook api中给出了一个java.net.unknownhost异常。
任何额外的信息都会很有帮助。:)

java.lang.RuntimeException: java.net.UnknownHostException: api.facebook.com
at com.google.code.facebookapi.BasicClientHelper.runtimeException(BasicClientHelper.java:123)
at com.google.code.facebookapi.ExtensibleClient.callMethod(ExtensibleClient.java:538)
at com.google.code.facebookapi.ExtensibleClient.callMethod(ExtensibleClient.java:446)
at com.google.code.facebookapi.ExtensibleClient.auth_createToken(ExtensibleClient.java:860)
at com.google.code.facebookapi.SpecificReturnTypeAdapter.auth_createToken(SpecificReturnTypeAdapter.java:73)
at facebookConnection.FbStartingPoint.<init>(FbStartingPoint.java:26)
at sourcepoint.FirstWindow$1.actionPerformed(FirstWindow.java:41)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.net.UnknownHostException: api.facebook.com
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.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.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at com.google.code.facebookapi.ExtensibleClient.postRequest(ExtensibleClient.java:583)
at com.google.code.facebookapi.ExtensibleClient.callMethod(ExtensibleClient.java:534)
... 41 more
z0qdvdin

z0qdvdin1#

api.facebook.com 是旧RESTAPI的终结点,已弃用;你可能应该连接到 graph.facebook.com 尽管如此,如果您使用的是遗留api,api.facebook.com应该是可解析的,并且仍然可以工作。
这几乎可以肯定是你的网络、防火墙、计算机、dns或jdk的问题——这是你连接到facebook的代码的问题,而不是facebook方面的问题

lztngnrs

lztngnrs2#

听起来你的机器无法访问 api.facebook.com 主人。您是否使用代理连接到internet?
尝试使用telnet以确保整个计算机都可以连接到internet(而不仅仅是代理配置的驱动程序):

> telnet api.facebook.com 80
Trying 66.220.149.99...
Connected to api.facebook.com.
Escape character is '^]'.
GET /

HTTP/1.1 400 Bad Request
Content-Type: text/html
Date: Sat, 25 Aug 2012 16:29:53 GMT
Connection: close
Content-Length: 134

<HTML><HEAD>
<TITLE>400 Bad Request</TITLE>
</HEAD><BODY>
<H1>Method Not Implemented</H1>
Invalid method in request<P>
</BODY></HTML>
Connection closed by foreign host.

相关问题