bobolounna / restfb

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

Facebook request failed (HTTP status code null) on simple example #174

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. run following block of code:
FacebookClient facebookClient = new DefaultFacebookClient();
Page page = facebookClient.fetchObject("cocacola", Page.class);
System.out.println("Page likes: " + page.getLikes());   

2. or even:
FacebookClient facebookClient = new DefaultFacebookClient("*********");
User user = facebookClient.fetchObject("me", User.class);
System.out.println("User name: " + user.getName());

What is the expected output? What do you see instead?
Expected output should be number of page likes for example #1 and my username 
for example #2

What version of the product are you using? On what operating system?
restFB 1.6.9, windows Vista 32

Please provide any additional information below.
Stack trace for both examples:
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:492)
    at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:469)
    at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:428)
    at com.restfb.DefaultFacebookClient.fetchObject(DefaultFacebookClient.java:238)
    at com.restfb.example.MojTest.main(MojTest.java:19)
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:337)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:612)
    at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:160)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:483)
    at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:278)
    at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:335)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:928)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
    at com.restfb.DefaultWebRequestor.executeGet(DefaultWebRequestor.java:99)
    at com.restfb.DefaultFacebookClient$2.makeRequest(DefaultFacebookClient.java:474)
    at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:490)

Original issue reported on code.google.com by zbub...@gmail.com on 9 Mar 2012 at 9:40

GoogleCodeExporter commented 8 years ago
Sorry, it seams problem was in my https proxy settings for JVM. I changed it 
and everything works ok.

Original comment by zbub...@gmail.com on 9 Mar 2012 at 10:12

GoogleCodeExporter commented 8 years ago
Thanks for letting me know.  Will close this one out.

Original comment by m...@xmog.com on 12 Mar 2012 at 6:51

GoogleCodeExporter commented 8 years ago
What did you change to get rid of this problem. We have the same issue here.

Original comment by moehrin...@googlemail.com on 9 Oct 2012 at 12:59

GoogleCodeExporter commented 8 years ago
Hi Moehrin,

I set-up my Java VM proxy settings because I tried to run this sample behing 
company proxy.
For example:
System.setProperty("http.proxyHost", "webcache.mydomain.com");
System.setPropery("http.proxyPort", "8080");

BR

Original comment by zbub...@gmail.com on 10 Oct 2012 at 8:39

GoogleCodeExporter commented 8 years ago
Hi I have same issue as yours and I tried to set the system properties in the 
code, but still same issue.
Can you clarify what you mean by setting them up on your Java VM, does that 
mean you put them somewhere else other than inside the code itself?

Would really appreciate the help.

P.S. I'm using fetchconnection instead of fetchobject does it matter?

Original comment by farah.e...@gmail.com on 29 Apr 2013 at 2:46

GoogleCodeExporter commented 8 years ago
Hi,
I just executed it on begining of my code (within main function) and it worked 
for rest of execution.
For long-time solution, you can google how to set-up your JVM to use proxy.

Original comment by zbub...@gmail.com on 29 Apr 2013 at 2:51

GoogleCodeExporter commented 8 years ago
Could you please tell me how it resolved your issue.  My working application 
suddenly not working with same exception. Am able to connect to other urls and 
verified java setting is fine with no proxy setting required. What else could 
be the reason?

Original comment by rathi.pr...@gmail.com on 5 Aug 2014 at 9:45

GoogleCodeExporter commented 8 years ago
Use this code for FacebooknetwaorException
public static void main(String[] args) {
    try {

        FacebookClient fbclient=new DefaultFacebookClient("CAACEdEose0cBAMZCEZCtNprks5s9erE9AaTVWQYmF06oCjwyPgfxOoKzdVT9dBIcdvRoeyxZC3DkE8MAPytdWAajlLFKcZAGmZBeXH38pPZCrLN87oMxZCIivyOm9yl7ZAdlyNdQ1ZBrfLZBYk2OdR2ZABQA621slnS7GG1x9DxbcPWPqhceapBTigJPTWBA2U1ZBSnkWHHerZBicyY7gF8LeqMXC");
           User user= fbclient.fetchObject("562659953878124", com.restfb.types.User.class);
           System.out.println(user.getBirthday()); 
         System.out.println(user.getFirstName()); 
           System.out.println(user.getGender()); 
           System.out.println(user.getId()); 
           System.out.println(user.getLastName()); 
        System.out.println(user.getBio());

} catch (FacebookJsonMappingException e) {
      // Looks like this API method didn't really return a list of users
    } catch (FacebookNetworkException e) {
      // An error occurred at the network level
        System.out.println("API returned HTTP status code " + e.getHttpStatusCode());
    } catch (FacebookOAuthException e) {
      // Authentication failed - bad access token?  
    } catch (FacebookGraphException e) {
      // The Graph API returned a specific error
        System.out.println("Call failed. API says: " + e.getErrorMessage());
    } catch (FacebookResponseStatusException e) {
      // Old-style Facebook error response.
      // The Graph API only throws these when FQL calls fail.
      // You'll see this exception more if you use the Old REST API
      // via LegacyFacebookClient.
      if (e.getErrorCode() == 200)
          System.out.println("Permission denied!");
    } catch (FacebookException e) {
      // This is the catchall handler for any kind of Facebook exception
    }

Original comment by pundu...@gmail.com on 26 Nov 2014 at 11:15