0

I want to get Facebook post's comments using HttpsUrlConnection this is url https://graph.facebook.com/399455050251075/comments?access_token={my_access_token}

String urlAddress = "https://graph.facebook.com/" + postId + "/comments?access_token=" + "{my_access_token}";
        try {
            URL url = new URL(urlAddress);
            HttpsURLConnection httpURLConnection = (HttpsURLConnection) url
                    .openConnection();
            httpURLConnection.setDoInput(true);
            httpURLConnection.setDoOutput(true);
            httpURLConnection.setReadTimeout(10000);
            httpURLConnection.setConnectTimeout(10000);
            httpURLConnection.setRequestMethod("GET");
            String response = ConnectionController.getResponse(httpURLConnection);
            Log.v(Constants.TAG, urlAddress);
            Log.v(Constants.TAG, response);

        } catch (IOException e) {
            e.printStackTrace();
        }

it is working on browser very well but in Android I get FileNotFoundException

Note: I don't want to use Facebook SDK or any other library

Ma7moud El-Naggar
  • 548
  • 1
  • 6
  • 18
  • Which file is not found? This seems like a problem with your build rather than the API – Igy Oct 09 '15 at 19:25
  • not build problem , see this http://stackoverflow.com/questions/9365829/filenotfoundexception-for-httpurlconnection-in-ice-cream-sandwich – Ma7moud El-Naggar Oct 09 '15 at 19:29
  • Have you verified `postId` has the right value? And you do not actually have the curly braces around your access token, right? Do you get the same result if you write the full URL into your code as a static value, without putting variables into it? – CBroe Oct 09 '15 at 20:14
  • yes , i tried it in browser same url and it works – Ma7moud El-Naggar Oct 09 '15 at 21:27

1 Answers1

0

Remove the setDoOutput(true) call from your code. That is only needed when you are doing POST requests, and having it here for your GET request will result in a FileNotFoundException.

NoChinDeluxe
  • 3,446
  • 1
  • 16
  • 29
  • You should call `httpURLConnection.getResponseCode()` to see what error the server is returning. Also, make sure the server you are calling can handle Https instead of just Http. – NoChinDeluxe Oct 12 '15 at 14:11