I am working on an android app which links to facebook (using the following tuturoial – https://developers.facebook.com/docs/mobile/android/build/). However, I want to download and save a friend’s info page so my program can read more information which the Facebook API does not provide such as email or phone number. If I go with the routine listed below, Facebook will not see me as logged in. What approach should I take to do this?
public static void main(String[] args) {
try {
URL u = new URL("https://www.facebook.com/profile.php?id=********");//where id is your friend's profile ID
OutputStream out = new FileOutputStream("bob.html");
InputStream in = u.openStream();
DTD html = DTD.getDTD("html");
System.out.println(html.getName());
in.close();
out.flush();
out.close();
} catch (Exception e) {
System.err.println("Usage: java PageSaver url local_file");
}
}
There is no way using the Facebook API to get the phone number or email address of your Friends – believe me, I’ve tried, and its really annoying! However, I can see that its configured that way to help preserve privacy of the user.
If you want to get this information directly from a URL, you’ll probably need to simulate the logging in process of Facebook – ie send a POST message to http://www.facebook.com and parse through the Username and Password of your user. This would log you in, and create a session object. You should then be able to call the profile URL, pass in the session object, and it will return the information you need.
I should point out, however, that this kind of access is strictly forbidden by Facebook, and they have made it perfectly clear in their Terms of Service that they will ban any developers and apps that attempt to use this kind of procedure to access the profile pages. Refer to https://developers.facebook.com/policy/ for the developer Facebook policy.