java - Facebook Graph API SSL 套接字握手异常

标签 java facebook sockets facebook-graph-api ssl

这是我使用图形 API 测试 facebook 数据收集的示例程序。在我的整个项目中,我无法找到错误的根本原因。第一次从程序中收集数据。但第二次它显示 ssl 异常。

public class Testing {

    public static void main(String[] args) throws IOException {

        // Make a URL to the web page
        boolean flag=false;
        int count=0;
        while(true)
        {

            count++;

            if(count==2)
            {

                flag=false;
            }

        System.out.println(new Date());
        URL url = new URL("https://graph.facebook.com/fql?q=select+message,post_id,created_time,actor_id,attachment,comments,created_time,impressions,likes,message_tags,place,share_count+from+stream+where+source_id+in(select+page_id+from+page+where+username=%27ATT%27)+and+created_time>1368439594&access_token=[HERE STANDS MY ACCESSTOKEN]");
        System.out.println(new Date());
        // Get the input stream through URL Connection
        URLConnection con = url.openConnection();
        InputStream is =con.getInputStream();

        // Once you have the Input Stream, it's just plain old Java IO stuff.

        // For this case, since you are interested in getting plain-text web page
        // I'll use a reader and output the text content to System.out.

        // For binary content, it's better to directly read the bytes from stream and write
        // to the target file.


        BufferedReader br = new BufferedReader(new InputStreamReader(is));

        String line = null;

        // read each line and write to System.out
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }

        }
    }
}

请指导我解决这个问题。

错误:

线程“main”中的异常 javax.net.ssl.SSLHandshakeException:握手期间远程主机关闭连接 在 sun.security.ssl.SSLSocketImpl.readRecord(未知来源) 在 sun.security.ssl.SSLSocketImpl.performInitialHandshake(未知来源) 在 sun.security.ssl.SSLSocketImpl.startHandshake(未知来源) 在 sun.security.ssl.SSLSocketImpl.startHandshake(未知来源) 在 sun.net.www.protocol.https.HttpsClient.afterConnect(未知来源) 在 sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(未知来源) 在 sun.net.www.protocol.http.HttpURLConnection.getInputStream(未知来源) 在 sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(未知来源) 在 span.com.Testing.main(Testing.java:28) Caused by: java.io.EOFException: SSL peer shutdown 不正确 在 sun.security.ssl.InputRecord.read(未知来源) ... 9 更多

最佳答案

您的 URL 是 HTTPS URL,这意味着它使用 SSL 但您尝试使用 URLConnection 打开连接。要打开 HTTPS URL,您应该使用 HttpsURLConnection:

final HttpsURLConnection con = (HttpsURLConnection) url.openConnection();

有了这个改变,它对我有用。 ;)

关于java - Facebook Graph API SSL 套接字握手异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30214224/

相关文章:

iOS、Facebook SDK。群组页面的“点赞”按钮具体示例?

php - Facebook 登录 App Review 要求您在批准项目之前使用项目显示 App。如何解决这个先有鸡还是先有蛋的难题?

java - 如何将数据发送到另一个Android应用程序并接收处理后的数据?

java - 在 N 个线程中并行运行相同的测试 M 次

iphone - 在 iPhone 应用程序的 Facebook 视频中标记 friend

java - ServerSocket 接受方法 - 如何向下转换为子类类型?

Android 套接字编程... 给出了什么?

java - 如何动态更改 JFrame 内的 JPanel?

java - 我如何使用 Jsoup 获取此文本?

java - 我应该在何时何地使用 close() 方法来避免 ObjectInputStream 中的 IOException?