0

I have created a code that checks if user is logged into Facebook. This is how it looks like:

URL url = new URL("https://graph.facebook.com/me?access_token=" + this.fb_token);
System.out.println("Attempting to open connection");
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();

int responseCode = conn.getResponseCode();
System.out.println(responseCode);
BufferedReader reader;
if(responseCode != 200) {
        reader = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
    }
    else{
        reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
    }

String json = reader.readLine();

reader.close();
conn.disconnect();

return json;

Next, I parse the Json, check if it's en error or data code and log the user.

My question is: Is if(responseCode != 200) check enough? Can Facebook return a different status code in case of successful authentication?

  • No, no need to check other code for successful authenticatoin. – Jay Prakash Oct 18 '16 at 08:54
  • Where are you getting the token from? And why do you need to perform this check? – CBroe Oct 19 '16 at 11:22
  • I have a client application and a server. Client performs login on his device and sends the token to my server. On the server I need to confirm if he's really logged to FB. It works now, I read somewhere that 200 is the only correct https code. –  Oct 19 '16 at 12:58

0 Answers0