ios - Facebook 好友列表突然返回 null

标签 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];
}

这些都很好,但是 friend 列表突然空了(Empty Json),有什么建议吗?

最佳答案

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

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

"权限

要查看当前人的 friend ,需要具有 user_friends 权限的用户访问 token 。 这只会返回任何使用过(通过 Facebook 登录)发出请求的应用程序的 friend 。”

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

关于ios - Facebook 好友列表突然返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23474737/

相关文章:

ios - 单击按钮滚动 UIScrollView

objective-c - 为什么 ((self=[super init]]) 有效,但 (!(self=[super init])) 无效?

objective-c - 从弹出窗口呈现 View

ios-Facebook SDK 3.0 发布状态更新时报错5

ios - PFFacebookUtils logInInBackgroundWithReadPermissions : block: opens Facebook app instead of using system account

objective-c - ios 6 uilabel 文本不居中对齐

ios - AdBanner 未在模拟器中显示

ios - 线程1 : EXC_BAD_ACCESS (code=2, 地址=0x16f913820)

ios - 更改 GMSPlacePicker 中的搜索文本颜色

ios - objective-c - iOS 10 Facebook 登录空白屏幕