Raon
Raon

Reputation: 1286

Getting null values in FB request response dictionary

I am trying to fetch all list of albums in a logged in facebook account with the following code... But unfortunately i am not able to get any list at all th result is dictionary..is like

{
    data =     (
    );
}

Any idea what i did wrong in the below code...

 FBRequest* friendsRequest = [FBRequest requestForGraphPath:@"me/albums"];

   [friendsRequest startWithCompletionHandler: ^(FBRequestConnection*connection,NSDictionary* result,NSError *error) {
                                                          if(!error)

                                                       {
                                                              NSLog(@"%@",result);
                                                              //NSArray *albums;


                                                          }

Here is the full method

- (BOOL)retrieveFacebookPhotosWithCompletionBlock:(void (^)(NSArray *, NSError *))completionBlock
{
    //FBSession *activeFBSession=[FBSession activeSession];

    //activeFBSession.state;


    [FBSession openActiveSessionWithReadPermissions:nil
                                       allowLoginUI:YES
                                  completionHandler:^(FBSession *session,
                                                      FBSessionState state,
                                                      NSError *error) {
                                      if (error) {

                                          NSLog(@"Error");
                                      } else if (session.isOpen) {

                                          [[FBRequest requestForMe] startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
                                              if (error) {
                                                  //error
                                                  completionBlock(nil, error);
                                              }else{
                                                  FBRequest* friendsRequest = [FBRequest requestForGraphPath:@"me/albums"];

                                                  [friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,NSDictionary* result,NSError *error) {
                                                      if(error)
                                                          completionBlock(nil, error);
                                                      else
                                                      {
                                                          NSLog(@"%@",result);
                                                          //NSArray *albums;


                                                      }
                                                  }];
                                              }
                                          }];

                                      }
                                  }];



        return YES;
}

Upvotes: 0

Views: 492

Answers (3)

Mini
Mini

Reputation: 213

Yes it is because of the permissions you have given .As mentioned above you have to give permission for accessing photos via key user_photos. Either you can refer the sample project provided by facebook SDk for more keys and the particular permissions each offer.or the facebook developer page.

Upvotes: 1

kaar3k
kaar3k

Reputation: 994

To get access to photos you need user_photos permission while you open the Facebook session.Try to change the code as below.

[FBSession openActiveSessionWithReadPermissions:
[NSArray arrayWithObjects:@"user_photos",nil] allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
                                         //YOUR CODE
                                           }];

Upvotes: 1

Anurag Kabra
Anurag Kabra

Reputation: 444

you need to get permission for "user_photos" for getting the albums.

When I tried it without the permissions then I received the same response as you. Using graph api explorer

When I got new access_token with permission than I received proper response from the api.

Upvotes: 1

Related Questions