0

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

3
  • Please call session.openForRead() to set the permissions Dec 4, 2013 at 6:56
  • know code is working, but no data ,12-03 23:58:47.215: I/FacebookActivity(24139): Online Friend Result: {Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"data":[]}}, error: null, isFromCache:false} when i runed fql query in graph api it workd there
    – pitu
    Dec 4, 2013 at 7:10
  • This is because the user didn't grant the permission to your app. You need to run the app again and make sure the permissions are asked when users is logged in for the first time. Dec 4, 2013 at 7:14

2 Answers 2

0

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

3
  • please check my edited questions, logcat shows App does not have permission to make this call
    – pitu
    Dec 4, 2013 at 6:42
  • know code is working, but no data ,12-03 23:58:47.215: I/FacebookActivity(24139): Online Friend Result: {Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"data":[]}}, error: null, isFromCache:false} when i runed fql query in graph api it workd there
    – pitu
    Dec 4, 2013 at 7:02
  • Hi Sunil, i have issue with online friend.The issue is when i login with developer account its showing all the friend who are in online.But when i login with different account then it showing only developer account is online(if it was online) and for remaining all friends its showing offline even some are in online.
    – sandeep
    Dec 23, 2013 at 9:41
0

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())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.