安卓得到Facebook上的朋友已经下载的应用程序谁 [英] Android get Facebook friends who have app downloaded
问题描述
我使用的是Facebook的Android SDK中。有一个简单的办法让谁下载了应用程序用户的好友?例如,应用程序画点什么实现了这一点。我似乎无法找到关于这个问题的任何信息
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
我猜想,如果有可能,一些额外的信息,将需要在httppost访问这些信息。
I would guess that if it was possible, some extra information would be needed in the httppost to access this information.
推荐答案
* 的注意:因为3.14版本,我的/朋友将只返回的朋友也使用该应用程序,所以下面的实现是德precated。看到新的Invitable朋友或Taggable朋友API的替代品。
* 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.
使用新的 Facebook的SDK为Android(3.0)是很容易得到用户的好友列表。 以下是code:
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!
}
});
}
然而,为了得到谁在使用你的Facebook应用程序的用户的朋友有一点点复杂(因为Facebook的API文档)。但是,是,有可能
首先,创建您的要求:
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.
接下来,你可以使用上面code创建您的要求,然后让你的朋友们:
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();
}
请注意,使用这种通用的要求,你没有收到GraphUser列表作为响应。你需要以下code得到响应,GraphUser清单:
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);
}
现在你可以使用你的用户的好友列表,信息,如果您的每一个朋友使用你的Facebook应用程序:
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");
这篇关于安卓得到Facebook上的朋友已经下载的应用程序谁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!