使用RestFb时获取未知主机异常

时间:2016-03-07 06:08:29

标签: facebook-sdk-4.0 restfb

我想连接以使用restFb从facebook获取数据,但它会抛出未知主机异常。

我的代码

package com.resrfb;
import com.restfb.DefaultFacebookClient;
import com.restfb.FacebookClient;
import com.restfb.types.User;

public class SimpleMeExample {

    public static void main(String[] args) {


        FacebookClient facebookClient= new DefaultFacebookClient("Key");


        User user = facebookClient.fetchObject("me", User.class);

        System.out.println("User="+ user);
        System.out.println("UserName= "+ user.getUsername());
        System.out.println("Birthday= "+ user.getBirthday());

    }

}

此外,我想知道如何从使用restfb登录我的网络应用程序的任何用户获取数据,因为我在手动设置了如何在使用facebook sdk登录时为任何用户提供访问权限。

堆栈跟踪

Exception in thread "main" com.restfb.exception.FacebookNetworkException: A network error occurred while trying to communicate with Facebook: Facebook request failed (HTTP status code null)
    at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:1024)
    at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:952)
    at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:914)
    at com.restfb.DefaultFacebookClient.fetchObject(DefaultFacebookClient.java:392)
    at com.resrfb.SimpleMeExample.main(SimpleMeExample.java:14)
Caused by: java.net.UnknownHostException: graph.facebook.com
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:195)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:529)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:559)
    at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
    at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:272)
    at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:329)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:911)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:133)
    at com.restfb.DefaultWebRequestor.execute(DefaultWebRequestor.java:374)
    at com.restfb.DefaultWebRequestor.executeGet(DefaultWebRequestor.java:96)
    at com.restfb.DefaultFacebookClient$3.makeRequest(DefaultFacebookClient.java:965)
    at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:1022)
    ... 4 more

1 个答案:

答案 0 :(得分:0)

您的计算机无法连接到Facebook,此错误位于较低级别,而不依赖于RestFB。您应该检查DNS设置,主机文件和代理设置。