bobolounna / restfb

Automatically exported from code.google.com/p/restfb
0 stars 0 forks source link

Trying to hit facebook through RestFB api #83

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
belwo exception is thrown when trying to hit Facebook trhu RESTFB

com.restfb.FacebookNetworkException: A network error occurred while trying to 
communicate with Facebook: Facebook GET failed (HTTP status code null)
    at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:436)
    at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:374)
    at com.restfb.DefaultFacebookClient.fetchObject(DefaultFacebookClient.java:209)
    at com.restfb.example.Main.main(Main.java:62)
Caused by: javax.net.ssl.SSLHandshakeException: 
sun.security.validator.ValidatorException: PKIX path building failed: 
sun.security.provider.certpath.SunCertPathBuilderException: unable to find 
valid certification path to requested target

What steps will reproduce the problem?

1.package com.restfb.example;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.net.URLConnection;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

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

import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.*;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;

below is the code which is giving SSLException

import javax.net.ssl.X509TrustManager;

/**
*
* @author sknavin
*/
public class Main {

         public static void main(String[] args) throws Exception {
            // SSLContext ctx = SSLContext.getInstance("TLS");
            // ctx.init(new KeyManager[0], new TrustManager[] {new DefaultTrustManager()}, new SecureRandom());
            // SSLContext.setDefault(ctx);

             URL yahoo = new URL("https://developers.facebook.com");

             String access_token="158461517517646|7aea7c8d8f825b9622535f91-100001692037134|6OKooGVzS5IFMGoSE1kiWjukEZI";

             FacebookClient facebookClient = new
             DefaultFacebookClient(access_token); 

             System.setProperty("http.proxyHost","internetpu");
             System.setProperty("http.proxyPort","8085");
             System.setProperty("https.proxyHost","internetpu");
             System.setProperty("https.proxyPort","8085");
             System.setProperty("proxySet","true");

             try {
                 User user = facebookClient.fetchObject("me", User.class);
         } catch (FacebookException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
         } 
           //  URLConnection yc = yahoo.openConnection();
          //   BufferedReader in = new BufferedReader(
          //                           new InputStreamReader(
          //                           yc.getInputStream()));
           // String inputLine;
//
       //      while ((inputLine = in.readLine()) != null) 
         //        System.out.println(inputLine);
      //       in.close();
         }

/**
* @param args the command line arguments
*/
} 

What is the expected output? What do you see instead?

I need to hit Facebook thru this code. How to resolve above error.
Also any idea about DefaultTrustManager. This class is not available.
I have inculded jsse.jar

Please provide any additional information below.

Original issue reported on code.google.com by aniketdo...@gmail.com on 18 Oct 2010 at 10:47

GoogleCodeExporter commented 8 years ago
This has nothing to do with restfb. Try accessing Facebook without the proxy 
and see if it solves your problem - I'd bet it does.

I'm guessing that you're usings self-signed SSL certs on your SSL proxy host.

-> http://blogs.sun.com/andreas/entry/no_more_unable_to_find
-> http://www.java-samples.com/showtutorial.php?tutorialid=210

Original comment by marcel@frightanic.com on 7 Nov 2010 at 12:10

GoogleCodeExporter commented 8 years ago
This is an SSL config issue that's unrelated to RestFB per Marcel's comment.  
Closing out as invalid.

Original comment by mark.a.a...@gmail.com on 12 Nov 2010 at 9:13

GoogleCodeExporter commented 8 years ago
I stepped on the exact same issue. I am trying on my local machine with 
localhost and there is no proxy anywhere. This 
http://blogs.sun.com/andreas/entry/no_more_unable_to_find does not solve the 
problem.

However, I do agree that it has something to do with machine. The code does not 
work on my Ubuntu 9.10 machine. But, it does work on my Windows machine.

I guess I wanted to say that if anyone stepping on the same issue, please 
consider trying on some other machine some, other settings.

Nishant

Original comment by nishant....@gmail.com on 14 Dec 2010 at 8:06