简体   繁体   中英

Facebook user_friends permission no longer returning friends who use the app after changing app name

I've been using the Facebook SDK in my iPhone app, logging in the users with an FBLoginView placed in an Interface Builder XIB file and initialized in the view controller .m file's delegate method like so:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    self.loginView = [self.loginView initWithReadPermissions: @[@"public_profile", @"user_friends"]];
    self.loginView.delegate = self;
}
return self;
}

I try to get the friend list after the user has logged in like this:

FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
                                              NSDictionary* result,
                                              NSError *error) {
    NSArray* friends = [result objectForKey:@"data"];
}

I have two Facebook accounts using my app, so one should be able to retrieve the other in this request. It was working fine and retrieving the friend until today, when I tried to change the app name. Now, friends ends up being an empty array. I've tried deleting then reauthorizing the app on both accounts. I've ensured that both accounts are friends on Facebook. I'm stuck and out of options, just as I was about to submit my finished app to the App Store review!

My App ID on Facebook and my FaceBookAppID in my app-Info.plist are the same and never have changed. The only differences between before and now: I changed my app's bundle ID on developers.facebook.com, making it the same as my Bundle Identifier in my PLIST. My Display Name and my FacebookDisplayName in my PLIST were both changed and are now the same.

I found the answer. I was looking in the wrong place; the problem had nothing to do with the name change on Facebook. This code in my question, as I found out, was being called after the XIB had already called init on loginView , which was giving it only the public profile by default. Calling initWithReadPermissions afterward wasn't adding any more permissions; in fact, this call seemed to be ignored:

UPDATE: Actually, looking back on this, I think the issue was that I was calling initWithReadPermissions on my FBLoginView before it was even allocated. Newbie mistake on my part.

self.loginView = [self.loginView initWithReadPermissions: @[@"public_profile", @"user_friends"]]; // loginView is an FBLoginView 

But this works if I put it in viewDidLoad and remove the other code:

self.loginView.readPermissions = @[@"user_friends"];

I must have only noticed this problem after the name change because I deleted the app from my accounts and re-added it, erasing the old user_friends permissions that had been granted before I was using a XIB for this view controller. Then I blamed the name change for it and searched fruitlessly on the Facebook dev site.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM