Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move to the next page in Facebook JSON response using iOS SDK?

In Facebook iOS SDK, I can ask for queries like this:

[_facebook requestWithGraphPath:@"me/feed" andDelegate:self];

But often Facebook will give a limited JSON response with a URL to be used to request to move to earlier dates, for example. So in the JSON response, I'll have:

data =     ( /*things here... status updates, photos, etc...*/
    );
paging =     {
        next = "https://graph.facebook.com/me/feed?sdk=ios&sdk_version=2&access_token= <something>&until=2010-12-04";
        previous = "https://graph.facebook.com/me/feed?sdk=ios&sdk_version=2&access_token=<something>&since=<something>";
    };

What I'm wondering is... How do I go to the previous URL? Does the SDK provide an interface to do this?

EDIT: If possible, I actually want answer with Graph API, as Facebook is currently deprecating the REST API.

BONUS: If anyone can explain the time format that's returned by Facebook. I have 2010-09-13T00%3A25%3A16%2B0000 as an example.

like image 560
Enrico Susatyo Avatar asked Jan 27 '11 05:01

Enrico Susatyo


2 Answers

all what you need that add a method to the Facebook subclass or itself

- (void)requestWithURLString:(NSString *)fullURL
               andHttpMethod:(NSString *)httpMethod
                 andDelegate:(id <FBRequestDelegate>)delegate {
    [self openUrl:fullURL params:nil httpMethod:httpMethod delegate:delegate];
}

ps the second param "httpMethod" may be always @"GET" you can omit it

like image 180
UIBuilder Avatar answered Nov 09 '22 03:11

UIBuilder


With Facebook's iOS SDK version 3 out, the original answer no longer applies to the current version.

I had to do some digging, because the new version doesn't make this any easier. I found an example of how to get this done in the FBGraphObjectPagingLoader class that the new SDK provides to help do this for tables. It's incredibly ugly, but I assume that it's the "recommended" method since it's what they use.

Here's my slight modification of their code (found originally in FBGraphObjectPagingLoader's followNextLink method)

FBRequest *request = [[[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:nil] autorelease];
FBRequestConnection *connection = [[[FBRequestConnection alloc] init] autorelease];
[connection addRequest:request completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
     // Do some stuff
 }];

// Override the URL using the one passed back in 'next'.
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:url];
connection.urlRequest = urlRequest;

[connection start];

You could of course modify their library and encapsulate this in the class itself if you wanted to.

like image 25
DougW Avatar answered Nov 09 '22 02:11

DougW