简体   繁体   中英

get online friend list using facebook sdk in android

i am trying to get all online friends of logedIn user of my app using facebook sdk, i have done some R&D but no use of it. though i am asking all related permissions but my code doesnt work,please correct me were i am going wrong.

log cat shows "App does not have permission to make this call"

below is my code permission list

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);
         }
    }

how to get this done ,thank you

You can use the following query to get the list of online and idle users.

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";

UPDATE

Please add friends_online_presence & user_online_presence permission

You need the user_status permission to read the user's status and user_online_presence and/or friends_online_presence permissions for the online_presence.

Here is the full permissions list.

Along with this it requires a FQL query--- SELECT name,uid FROM user WHERE online_presence IN ('active', 'idle') AND uid IN ( SELECT uid2 FROM friend WHERE uid1 = me())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM