我们如何在iOS SDK中获取Facebook页面列表

时间:2015-04-08 07:32:53

标签: ios facebook facebook-graph-api

我已使用Facebook Graph API成功将用户登录到Facebook,现在我需要获取用户的Facebook页面列表(page status已更改为Published)。

我的代码如下:

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

回复:

pages result: {
                data = (); 
              }

请咨询。感谢。

1 个答案:

答案 0 :(得分:1)

您是否通过登录对话框请求了相应用户的manage_pages权限?您发布的代码看起来不错恕我直言,我认为您因为缺少权限而看到空结果。