尝试通过 RestFB 连接到 Facebook api 时出现 FacebookNetworkException

FacebookNetworkException while trying to connect to facebook api via RestFB

我正在尝试将我的应用程序连接到 Facebook API,但在执行代码时出现以下异常:

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 Test.main(Test.java:18)
Caused by: java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
    at javax.net.ssl.DefaultSSLSocketFactory.throwException(Unknown Source)
    at javax.net.ssl.DefaultSSLSocketFactory.createSocket(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.createSocket(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.plainConnect0(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.restfb.DefaultWebRequestor.execute(DefaultWebRequestor.java:374)
    at com.restfb.DefaultWebRequestor.executeGet(DefaultWebRequestor.java:96)
    at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:965)
    at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:1022)
    ... 4 more
Caused by: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
    at java.security.Provider$Service.newInstance(Unknown Source)
    at sun.security.jca.GetInstance.getInstance(Unknown Source)
    at sun.security.jca.GetInstance.getInstance(Unknown Source)
    at javax.net.ssl.SSLContext.getInstance(Unknown Source)
    at javax.net.ssl.SSLContext.getDefault(Unknown Source)
    at javax.net.ssl.SSLSocketFactory.getDefault(Unknown Source)
    at javax.net.ssl.HttpsURLConnection.getDefaultSSLSocketFactory(Unknown Source)
    at javax.net.ssl.HttpsURLConnection.<init>(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.<init>(Unknown Source)
    at sun.net.www.protocol.https.Handler.openConnection(Unknown Source)
    at sun.net.www.protocol.https.Handler.openConnection(Unknown Source)
    at java.net.URL.openConnection(Unknown Source)
    at com.restfb.DefaultWebRequestor.openConnection(DefaultWebRequestor.java:219)
    at com.restfb.DefaultWebRequestor.execute(DefaultWebRequestor.java:365)
    ... 7 more
Caused by: java.io.IOException: Invalid keystore format
    at sun.security.provider.JavaKeyStore.engineLoad(Unknown Source)
    at sun.security.provider.JavaKeyStore$JKS.engineLoad(Unknown Source)
    at sun.security.provider.KeyStoreDelegator.engineLoad(Unknown Source)
    at sun.security.provider.JavaKeyStore$DualFormatJKS.engineLoad(Unknown Source)
    at java.security.KeyStore.load(Unknown Source)
    at sun.security.ssl.TrustManagerFactoryImpl.getCacertsKeyStore(Unknown Source)
    at sun.security.ssl.SSLContextImpl$DefaultSSLContext.getDefaultTrustManager(Unknown Source)
    at sun.security.ssl.SSLContextImpl$DefaultSSLContext.<init>(Unknown Source)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    ... 21 more

我认为重要的是要提到我在尝试使用 facebook4j运行 编码时遇到了同样的异常

我花了很多时间想弄清楚,我真的卡住了。

测试代码class:

import com.restfb.DefaultFacebookClient;
import com.restfb.FacebookClient;
import com.restfb.Version;
import com.restfb.types.User;

public class Test {

    public Test() {
    }

    public static void main(String[] args) {

        String accessToken = "******";

        FacebookClient fc = new DefaultFacebookClient(accessToken, Version.UNVERSIONED); // Setting version has no effect

        User me = fc.fetchObject("me", User.class);

        System.out.println(me.getFirstName());
        System.out.println(me.getLanguages());
    }

}

好的,我尝试运行不同机器上的代码,结果发现开发环境的设置有问题。