我正在开发一款游戏,当我在Facebook接受邀请时,我会为玩家提供奖励币。我可以通过Facebook发送邀请。但如何知道是否有人接受邀请。
我打算做这样的事情,
如何在facebook android中获取已接受的应用程序请求列表。
答案 0 :(得分:0)
您需要先在此处创建FB应用。然后,当有人接受您的应用程序请求时,他会将您的应用程序列为其配置文件的已安装应用程序。
因此,如果用户A向B和Z发送邀请请求,B接受它并且Z拒绝它。现在,如果您从App获取A的朋友列表,您将获得一个布尔“已安装”。对于B,此布尔值将为True,对于Z,该布尔值将为False(或缺失)。
以下代码可以帮助您阅读此已安装的布尔值
private void requestMyAppFacebookFriendsWithAppInstalled(Session session) {
Request friendsRequest = createRequest(session);
friendsRequest.setCallback(new Request.Callback()
{
@Override
public void onCompleted(Response response)
{
//SetUpList
List<GraphUser> friends = getResults(response);
GraphUser user;
friendsList=new ArrayList<ACT_friendsListPicker.FB_FriendsListStructure>();
boolean installed = false;
if(friends!=null)
{
for(int count=0;count<friends.size();count++)
{
user = friends.get(count);
if(user.getProperty("installed") != null)
{
installed = (Boolean) user.getProperty("installed");
Log.i("frndsPickerAppInstalled? YES ","user: "+user.getInnerJSONObject());
}
}}}});
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","hometown",
"installed" };
fields.addAll(Arrays.asList(requiredFields));
Bundle parameters = request.getParameters();
parameters.putString("fields", TextUtils.join(",", fields));
request.setParameters(parameters);
return request;
}
private class FB_FriendsListStructure
{
String Name,ID,ImageUrl;
boolean selected;
}
private List<GraphUser> getResults(Response response) throws NullPointerException
{
try{
GraphMultiResult multiResult = response
.getGraphObjectAs(GraphMultiResult.class);
GraphObjectList<GraphObject> data = multiResult.getData();
return data.castToListOf(GraphUser.class);
}
catch(NullPointerException e)
{
return null;
//at times the flow enters this catch block. I could not figure out the reason for this.
}
}