Facebook好友列表突然返回null

时间:2014-05-05 14:16:25

标签: ios objective-c facebook-ios-sdk

我正在使用Facebook SDK 3.14(最新版),一切正常。然后昨天,它停止显示登录用户的好友列表。

这是我点击logIn buttonL

的时候
- (IBAction)buttonClickHandler:(id)sender {
// get the app delegate so that we can access the session property
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

// this button's job is to flip-flop the session from open to closed
if (appDelegate.session.isOpen) {
    // if a user logs out explicitly, we delete any cached token information, and next
    // time they run the applicaiton they will be presented with log in UX again; most
    // users will simply close the app or switch away, without logging out; this will
    // cause the implicit cached-token login to occur on next launch of the application
    [appDelegate.session closeAndClearTokenInformation];

} else {
    if (appDelegate.session.state != FBSessionStateCreated) {
        // Create a new, logged out session.
        appDelegate.session = [[FBSession alloc] init];
    }

    // Attempt to open the session. If the session is not open, show the user the Facebook login UX

    // if the session isn't open, let's open it now and present the login UX to the user
    [appDelegate.session openWithCompletionHandler:^(FBSession *session,
                                                     FBSessionState status,
                                                     NSError *error) {
        // and here we make sure to update our UX according to the new session state
        [self updateView];
    }];

}

}

updateView方法中,我调用了Facebook图形请求的JSON:

- (void)updateView {
// get the app delegate, so that we can reference the session property
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
if (appDelegate.session.isOpen) {
    // valid account UI is shown whenever the session is open

    selectedPageURL=[NSString stringWithFormat:@"https://graph.facebook.com/me/friends?access_token=%@&fields=name,id,picture,gender",
                     appDelegate.session.accessTokenData.accessToken];

    [self load_HTTPRequest:selectedPageURL];

    [FBSession setActiveSession:appDelegate.session];
    FBRequest *me = [FBRequest requestForMe];
    [me startWithCompletionHandler:^(FBRequestConnection *connection,
                                     id result,
                                     NSError *error) {
        NSDictionary<FBGraphUser> *my = (NSDictionary<FBGraphUser> *) result;

        self.name.text = my.name;
        [self.profile setImageWithURL:[NSURL URLWithString:[[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [my id]] stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]];
    }];

在AppDelegate中,这就是我所包含的内容:

    - (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
    // attempt to extract a token from the url
    return [FBAppCall handleOpenURL:url
                  sourceApplication:sourceApplication
                        withSession:self.session];
}

这些都很好,但突然朋友列表是空的(空Json),有什么建议吗?

2 个答案:

答案 0 :(得分:1)

我认为这是因为最后一个Facebook SDK只返回我们的朋友,允许该应用访问他们的个人资料信息。因此,我们的朋友列表将仅返回在请求之前允许应用程序的朋友。

正如您在下面看到的访问我们朋友列表的权限:

&#34;权限

需要具有user_friends权限的用户访问令牌才能查看当前此人的朋友。 这只会返回任何使用(通过Facebook登录)应用程序发出请求的朋友。&#34;

https://developers.facebook.com/docs/graph-api/reference/v2.0/user/friends/

答案 1 :(得分:0)

甚至Facebook android移动应用程序本身也显示相同的错误。

似乎Facebook的API中存在错误。

  1. 转到任何人的个人资料。
  2. 点击“好友”链接。
  3. 您将看到一个新窗口,显示“了解null的朋友”。