Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Facebook SDK 3.1 Retrieve friend birthday returning null

Tags:

ios

facebook

sdk

I'm trying to retrieve birthday data of facebook friends, but it's returning null. I'm using this code:

FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
                                  NSDictionary* result,
                                  NSError *error) {
    NSArray* friends = [result objectForKey:@"data"];
    NSLog(@"Found: %i friends", friends.count);
    for (NSDictionary<FBGraphUser>* friend in friends) {
        NSLog(@"I have a friend named %@ - birthday %@", friend.name, friend.birthday);
    }
}];

Friend name is ok, but friend birthday or all data that is not one of the basics friends data is returning null. Note i'm already added user_birthday and friends_birthday permissions in facebook.com app page and in openSession method (login):

- (void)openSession
{

    NSArray *permissions = [[NSArray alloc] initWithObjects:
                            @"user_birthday",
                            @"friends_birthday",
                            nil];


    [FBSession openActiveSessionWithReadPermissions:permissions
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session,
       FBSessionState state, NSError *error) {
         [self sessionStateChanged:session state:state error:error];
     }];
 }

Needing some help here, i've already tried everything.

like image 641
Daniel Campos Avatar asked Nov 01 '12 04:11

Daniel Campos


2 Answers

I have the same problem and i solve this way.

  • First of all, be sure that you have the correct permissions.

     NSArray *permissions = @[@"user_birthday", @"friends_hometown",
                            @"friends_birthday", @"friends_location"];
    [FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler: .....
    
  • Then, DO NOT USE requestForMyFriends. I try in several ways ( changing the FBRequest and this kind of things

  • Check the permissions and be sure that it was the permissions you need.

    NSLog(@"permissions::%@",FBSession.activeSession.permissions);
    
  • Now generate the FBRequest this way.

    FBRequest *friendRequest = [FBRequest requestForGraphPath:@"me/friends?fields=name,picture,birthday,location"];
     [ friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
        NSArray *data = [result objectForKey:@"data"];
        for (FBGraphObject<FBGraphUser> *friend in data) {
            NSLog(@"%@:%@", [friend name],[friend birthday]);
     }}];
    

I finally get this data. I hope it helps you

like image 191
jgorozco Avatar answered Nov 03 '22 08:11

jgorozco


In v2.0 of the Graph API, you cannot get a person's friends birthdays - the friends_birthday permission has been deprecated.

Read more about these changes here: https://developers.facebook.com/docs/apps/changelog

like image 44
Simon Cross Avatar answered Nov 03 '22 07:11

Simon Cross