Dharmendra Kumar Rajan
Dharmendra Kumar Rajan

Reputation: 229

How can we get Facebook Page List in iOS SDK

I have successfully logged user to Facebook using Facebook Graph API and now i need to fetch the user's Facebook page list (page status is already changed to Published).

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

Please Advice. Thanks.

Upvotes: 0

Views: 488

Answers (1)

Tobi
Tobi

Reputation: 31489

Have you requested the manage_pages permission from the respective user through the login dialog? The code you posted look ok IMHO, I think you see an empty result because of the missing permission.

Upvotes: 1

Related Questions