【问题标题】:Facebook invite friends and getting accepted friends listFacebook 邀请好友并获取已接受好友列表
【发布时间】:2014-04-15 08:11:18
【问题描述】:

我正在开发一个游戏,当在 facebook 中接受邀请时,我会为玩家提供奖励金币。我可以通过 facebook 发送邀请。但是如何知道是否有人接受了邀请。

我打算做这样的事情,

  1. 向朋友发送邀请 - 将他们的 ID 存储在 sqlite 中
  2. 获取接受好友列表 - 根据接受邀请的好友数量更新表格和奖励

如何在 facebook android 中获取接受的 App 请求列表。

【问题讨论】:

    标签: android facebook


    【解决方案1】:

    您需要先在此处创建一个 FB 应用程序。然后稍后当有人接受您的应用请求时,他会将您的应用列为他的个人资料的已安装应用。

    所以如果用户 A 向 B 和 Z 发送邀请请求。B 接受它而 Z 拒绝它。现在,如果您从您的应用程序中获取 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.
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-27
      相关资源
      最近更新 更多