IPhone : How can we get Facebook Page List in iOS SDK

on Wednesday, April 8, 2015

This is what i am looking for. I have successfully logged user to Facebook using FB.api and now i need to fetch the user's Facebook page list (page status is already changed to Published). I have one Facebook App which i am using to fetch Facebook page list and one FB login button through which the user login enabled. My code looks like




  • (void)checkLoginWithFacebook { // If the session state is any of the two "open" states when the button is clicked if (FBSession.activeSession.state == FBSessionStateOpen || FBSession.activeSession.state == FBSessionStateOpenTokenExtended) {



    // Close the session and remove the access token from the cache
    // The session state handler (in the app delegate) will be called automatically
    // If the session state is not any of the two "open" states when the button is clicked

    [self getListOfPages];


    } else { // Open a session showing the user the login UI // You must ALWAYS ask for basic_info permissions when opening a session



    // This will bypass the ios6 integration since it does not allow for a session to be opened
    // with publish only permissions!


    FBSession* sess = [[FBSession alloc] initWithPermissions:[NSArray arrayWithObjects:@"publish_actions",nil]];

    [FBSession setActiveSession:sess];
    [sess openWithBehavior:(FBSessionLoginBehaviorForcingWebView) completionHandler:^(FBSession *session, FBSessionState state, NSError *error)
    {

    [[AppDelegate appDel] sessionStateChanged:session state:state error:error];


    if (state == FBSessionStateClosed || state == FBSessionStateClosedLoginFailed)
    {

    NSLog(@"session closed");
    return ;
    }

    [self getListOfPages];
    }];


    }




}



  • (void)getListOfPages { [FBRequestConnection startWithGraphPath:@"/me/accounts" completionHandler:^( FBRequestConnection *connection, id result, NSError error ) { / handle the result */ NSLog(@"pages result: %@ ",result); }]; }


Response: pages result: { data = (); }


0 comments:

Post a Comment