javahttprequestrestfb

How can I shorten timeout times using restfb request?


I am using FacebookClient class and publish function when requesting. I want to shorten timeout times. How can I do it?


Solution

  • You have to extend the DefaultWebRequstor class and override the customizeConnection method. There you can modify the connection object and set your custom timeout.

    @Override
    protected void customizeConnection(HttpURLConnection connection) {
      connection.setReadTimeout(YOUR_VALUE_IN_MS);
    }
    

    Afterwards you have to use this custom web requestor in the constructor of the DefaultFacebookClient class.

    FacebookClient client = 
      new DefaultFacebookClient(ACCESS_TOKEN, 
                             new CustomWebRequestor(), // your requestor
                             new DefaultJsonMapper(), 
                             Version.LATEST);
    

    And you're done. With this method you can modify the connection even further.