我们如何在 iOS SDK 中获取 Facebook 页面列表
How can we get Facebook Page List in iOS SDK
我已使用 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 = ();
}
请指教。谢谢。
您是否通过登录对话框请求了相应用户的 manage_pages
权限?您发布的代码看起来不错恕我直言,我认为您看到的是空结果,因为缺少权限。
我已使用 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 = ();
}
请指教。谢谢。
您是否通过登录对话框请求了相应用户的 manage_pages
权限?您发布的代码看起来不错恕我直言,我认为您看到的是空结果,因为缺少权限。