Ad

How To Use Facebook Pagination In Ios

Hi I have recently started coding for iOS.I am trying to get videos from facebook using the following code.

-(void)facebookGetVideos:(UIViewController*)vc completionHandler:(void (^)(NSMutableArray*))completionBlock{
   __block NSMutableArray * itemArray;
    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]

                                  initWithGraphPath:@"me/videos/uploaded"

                                  parameters:@{@"fields":@"source,description,thumbnail,title"}

                                  HTTPMethod:@"GET"];

    [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                          id result,

                                          NSError *error) {
        if(error!=nil){
             NSLog(@"Error after fb dwnld %@",error);
            [MBProgressHUD hideHUDForView:vc.view animated:true];
            [self showAlert:@"Error" message:error.localizedDescription viewController:vc];
        }else{

            NSLog(@"Results %@",result);
             itemArray = [[NSMutableArray  alloc]init];
           // [itemArray addObject:[result valueForKey:@"data"]];
            itemArray =[result valueForKey:@"data"];

             completionBlock(itemArray);
        }
    }];

}

The response I am getting from there is as below:-

{
    data =     (
                {
            id = 1845903302379295;
            source = "https://video.xx.fbcdn.net/v/t43.1792-2/27475816_220074475216744_8742438766032977920_n.mp4?efg=eyJybHIiOjE1MDAsInJsYSI6MTAyNCwidmVuY29kZV90YWciOiJzdmVfaGQifQ%3D%3D&rl=1500&vabr=382&oh=d4c3f6028a979c5919fdd8e444e24179&oe=5A89882A";
        },
                {
            id = 1814936632142629;
            source = "https://video.xx.fbcdn.net/v/t42.14539-2/23925286_2650490725061654_2502749796398268416_n.mp4?efg=eyJybHIiOjU3NiwicmxhIjo1MTIsInZlbmNvZGVfdGFnIjoic2QifQ%3D%3D&rl=576&vabr=320&oh=2fde1aea6eff33d8139ccb8fe7a33fd4&oe=5A8980C0";
        }
    );
    paging =     {
        cursors =         {
            after = MTgxNDkzNjYzMjE0MjYyOQZDZD;
            before = MTg0NTkwMzMwMjM3OTI5NQZDZD;
        };
    };
}

I am trying to use this after before as parameters as below:-

-(void)afterValues:(NSString*)afterVal{


    NSDictionary * parameters [email protected]{@"fields":@"source",@"after": afterVal};
    FBSDKGraphRequest *request1 = [[FBSDKGraphRequest alloc]
                                   initWithGraphPath:@"me/videos/uploaded"
                                   parameters:parameters
                                   HTTPMethod:@"GET"];
    [request1 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                           id result,
                                           NSError *error) {

        NSLog(@"after videos%@",result);


    }];
}

And getting the following as response:-

after videos{
    data =     (
    );
}

Can anyone please point out at my mistake.Any kind of help/suggestion or guidance in this directions would be highly appreciated.Thanks in advance!

Ad

Answer

Have you requested the manage_pages permission from the respective user through the login dialog? I think you see an empty result because of the missing permission.

Ad
source: stackoverflow.com
Ad