简体   繁体   中英

How to load friend's facebook info with my Android app

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.

You logged as facebook user, using facebook instance: facebook.request("me"); u get ur details as JSON object. from which u can details as

String name = json.getString("name");
        String email = json.getString("email");
        String gender = json.getString("gender");
        String id = json.getString("id");

for frends : facebook.request("me/friends"); u get ur frends details as JSON Array from which u can get frends details as JSON objects.

Use the Facebook Graph API and ask for required permissions.

You need the extended permission

email

to read a user's email.

There is no equivalent permission for friends' emails. You can only get the email of the logged in user.

You get the email by calling:

https://graph.facebook.com/me

after user log-in, ie you need access token.

Phone number is not accessible via API as far as I know.

You access your friends' basic info by calling:

https://graph.facebook.com/USER_ID

and by adding these permissions you can get more detailed info from the "/USER_ID" call:

friends_about_me
friends_interests
friends_relationships
friends_birthday
friends_hometown
friends_location   

However, the "/USER_ID" call doesn't return all the user data you can see on the info page on the web. You can access additional info via these calls:

/USER_ID/interests

returns the interests listed on the user's profile and requires the user_interests permission

/USER_ID/music

returns music listed on the user's profile

/USER_ID/books

returns books listed on the user's profile

/USER_ID/movies

returns movies listed on the user's profile

/USER_ID/television

returns television listed on the user's profile

/USER_ID/likes

returns all the pages this user has liked and requires the user_likes permission

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM