I am using the Facebook Android SDK. Is there an easy way to get a user's friends who have downloaded the app? For example, the app Draw Something implements this. I can't seem to find any information on this subject
I would guess that if it was possible, some extra information would be needed in the httppost to access this information.
Before you can share to Facebook from your app, you to link or download the Facebook Sharing SDK for Android. The Sharing SDK for Android is a component of the Facebook SDK for Android. To use the Facebook Sharing SDK in your project, make it a dependency in Maven, or download it.
If you don't have a Facebook App ID for your app yet, see Facebook SDK Quick Start for Android. Find your Facebook App ID on the Apps page of the developer portal and then see Add Your Facebook App ID and Client Token. Generate an Android development key hash and add it to the Sample Apps page of your developer settings.
How to Download Friends Mapper on Facebook 1 To begin make sure you have an internet connection 2 Open the google chrome browser 3 Visit the Google Chrome Webstore 4 Search for the “Facebook Friend Mapper” using the search icon 5 Once seen click add to chrome 6 Install the “Facebook Friend Mapper” 7 Add the extension to your chrome
To use the Facebook Sharing SDK in your project, make it a dependency in Maven. Build your project. Get your Facebook App ID properly configured and linked to your Android app. If you don't have a Facebook App ID for your app yet, see Facebook SDK Quick Start for Android.
* Note: since 3.14 version, me/friends will only return friends that also use the app, so below implementation is deprecated. See the new "Invitable Friends" or "Taggable Friends" APIs for alternatives.
Using the new Facebook SDK for Android (3.0) is very easy to get your user's friend list. Following is the code:
private void requestFacebookFriends(Session session) {
Request.executeMyFriendsRequestAsync(session,
new Request.GraphUserListCallback() {
@Override
public void onCompleted(List<GraphUser> users,
Response response) {
// TODO: your code for friends here!
}
});
}
Nevertheless, in order to get the user's friends who are using your Facebook app is a little bit complicated (due to Facebook API documentation). But yes, it is possible.
First of all, create your request:
private Request createRequest(Session session) {
Request request = Request.newGraphPathRequest(session, "me/friends", null);
Set<String> fields = new HashSet<String>();
String[] requiredFields = new String[] { "id", "name", "picture",
"installed" };
fields.addAll(Arrays.asList(requiredFields));
Bundle parameters = request.getParameters();
parameters.putString("fields", TextUtils.join(",", fields));
request.setParameters(parameters);
return request;
}
Note that you need to insert the field "installed" in your request. I'm requesting the user picture path with the same request. Check your possibilities here.
Next, you can use above code to create your request and then get your friends:
private void requestMyAppFacebookFriends(Session session) {
Request friendsRequest = createRequest(session);
friendsRequest.setCallback(new Request.Callback() {
@Override
public void onCompleted(Response response) {
List<GraphUser> friends = getResults(response);
// TODO: your code here
}
});
friendsRequest.executeAsync();
}
Note that using this generic request, you don't receive a GraphUser list as response. You'll need following code to get the response as GraphUser list:
private List<GraphUser> getResults(Response response) {
GraphMultiResult multiResult = response
.getGraphObjectAs(GraphMultiResult.class);
GraphObjectList<GraphObject> data = multiResult.getData();
return data.castToListOf(GraphUser.class);
}
Now you can use your user's friend list, with the information if each of your friends use your Facebook app:
GraphUser user = friends.get(0);
boolean installed = false;
if(user.getProperty("installed") != null)
installed = (Boolean) user.getProperty("installed");
I implemented it in this way
Bundle params = new Bundle();
params.putString("fields", "name, picture, location, installed");
And during displaying of the items on the list,in the getView() method i did this
boolean b = jsonObject.getBoolean("installed");
if (b){
Log.d("VIVEK",jsonObject.getString("name"));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With