5

I synced my address book with facebook and can now access my facebook profile through my addressbook. I want to read the facebook data that is connected to the account from another application and get the facebook id of the synced user.

I can't find a mimetype or a datafield in the ContactContracts.Data table that contains something related to facebook. Has anybode done this successfully?

It seems that facebook somehow restricts the permissions to this data. How is this done and which permissions do I need to access the facebook contact informations that are synced in the address book?

Janusz
  • 187,060
  • 113
  • 301
  • 369

3 Answers3

3

If the user has that info in their contacts, then they are also friends with that person on facebook. Just use the graph api and get the list of friends and filter them with the contact name selected or let the user select from a listview which is made from the returned names of the facebook api query.

try {
    JSONObject response = Util.parseJson(facebook.request(
    "/me/friends", new Bundle(), "GET"));

    JSONArray jArray = response.getJSONArray("data");

    for (int i = 0; i < jArray.length(); i++) {
        JSONObject json_data = jArray.getJSONObject(i);
        tempMap = new HashMap<String, Object>();
        tempMap.put("friend", json_data.getString("name"));
        tempMap.put("id", json_data.getString("id"));
        friendlist.add(tempMap);
    }
} catch (MalformedURLException e) {
    e.printStackTrace();
} catch (JSONException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
} catch (FacebookError e) {
    e.printStackTrace();
}
Anthony Graglia
  • 5,355
  • 5
  • 46
  • 75
  • Sure that is possible, but is much more work then just look into to the contacts api. and facebook can do better merges with the user in the addressbook because it can access private data of my friends like their email address. – Janusz Jan 20 '11 at 15:05
  • In your question, you say want facebook info of that user... you can pass the id back and get all the info back in JSON format and step into "data". Perhaps you can be more clear and which pieces you are looking for. If you only want email, there are better ways yet. – Anthony Graglia Jan 23 '11 at 14:41
  • I want to access the facebook id belonging to a user in my address book. And since facebook already did the merging of address book entries and friends on facebook for me I would like to do it through the contacts API and not the facebook graph API – Janusz Jan 24 '11 at 08:35
0

You can also consider working with the APIs and android SDK offered by gigya.com (where I used to work until recently).

epeleg
  • 10,347
  • 17
  • 101
  • 151
0

It seems that this is not possible to the official API until now because of this exception that was made for the facebook app by google. I hope facebook complies with the offical android API in its next versions.

Janusz
  • 187,060
  • 113
  • 301
  • 369