在android中使用facebook sdk获取在线好友列表

时间:2013-12-04 06:28:21

标签: android facebook

我正在尝试使用facebook sdk获取我的应用程序的logedIn用户的所有在线朋友, 我已经完成了一些R& D但没有使用它。 虽然我问所有相关的权限,但我的代码不起作用,请纠正我,我错了。

log cat显示“应用程序无权进行此调用”

下面是我的代码 许可清单

private static final List<String> PERMISSIONS = Arrays
            .asList("publish_actions" ,"user_likes","friends_likes","manage_pages","publish_stream","user_status", "user_online_presence", "friends_online_presence");

public void getOnlineFreindList() {
        Log.i("inside", "requestfriend()");
        Session session = Session.getActiveSession();
         if (session != null)
         {
          List<String> permissions = session.getPermissions(); 
          if (!isSubsetOf(PERMISSIONS, permissions))
          { pendingPublishReauthorization = true; 
            Session.NewPermissionsRequest   newPermissionsRequest = new Session .NewPermissionsRequest(this,PERMISSIONS);
            session.requestNewPublishPermissions(newPermissionsRequest);
            return;
          }

        String fqlQuery = "SELECT name,uid FROM user WHERE online_presence IN ('active', 'idle') AND uid IN ( SELECT uid2 FROM friend WHERE uid1  ="+"100006508492702"+")";

        Bundle params = new Bundle();
        params.putString("q", fqlQuery);
        //Session session = Session.getActiveSession();
        Request request = new Request(session, "/fql", params, HttpMethod.GET,
                new Request.Callback() {
                    public void onCompleted(Response response) {
                        Log.i(TAG,
                                "Online Friend Result: " + response.toString());
                        Toast.makeText(Facebook.this, response.toString(),
                                Toast.LENGTH_LONG).show();
                    }
                });
        Request.executeBatchAsync(request);

        // init();
        // requestMyAppFacebookFriends(session);
         }
    }

如何完成这项工作,谢谢

2 个答案:

答案 0 :(得分:0)

您可以使用以下查询来获取在线和空闲用户列表。

String fqlQuery = "SELECT uid, name, pic_square, online_presence FROM user " +
                  "WHERE online_presence IN ('active', 'idle') " +
                  "AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) 
                   ORDER BY name";

<强>更新

请添加friends_online_presence&amp; user_online_presence权限

答案 1 :(得分:0)

您需要 user_status 权限才能阅读 online_presence的用户状态和 user_online_presence 和/或 friends_online_presence 权限。

Here是完整的权限列表。

除此之外,还需要一个FQL查询--- SELECT name,uid FROM user WHERE online_presence IN('active','idle')AND uid IN(SELECT uid2 FROM friend WHERE uid1 = me())