Reputation: 19800
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.
Upvotes: 8
Views: 5247
Reputation: 30055
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.
Upvotes: 6
Reputation: 1730
At least as far as the date format goes, its a variant of RFC 3339 format. As far as I know, iOS doesn't have a pre-defined formatter of that type.
I create a date formatter and keep it around (they're are strangely slow to create) so I can easily convert them when working with FB data.
NSDateFormatter * sRFC3339DateFormatter = nil;
NSLocale * enUSPOSIXLocale;
sRFC3339DateFormatter = [[NSDateFormatter alloc] init];
enUSPOSIXLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease];
[sRFC3339DateFormatter setLocale:enUSPOSIXLocale];
[sRFC3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ssZ"];
[sRFC3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
Once you have such a formatter, you can easily convert back and forth.
NSDate* myDate = nil;
myDate = [sRFC3339DateFormatter dateFromString:@"2011-01-27T04%3A48%3A50%2B0000"];
Breaking the URL up into a dictionary of strings is pretty straightforward with NSURL methods.
Upvotes: 0
Reputation: 1333
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
Upvotes: 7
Reputation: 13137
You can do something like this:
[appDelegate.fb requestWithGraphPath:@"me/home"
andParams:[NSMutableDictionary dictionaryWithObject:@"2011-01-27T04%3A48%3A50%2B0000" forKey:@"since"]
andDelegate:self];
Notice that, in the paging
portion of your feed, the next
and previous
URLs differ just by one query parameter (until
and since
). You can use the values you grab from this to get the next and previous page of results.
Hope this helps!
Upvotes: 2
Reputation: 1480
Yes you can get the result by calling the function in api I used below code to get the statuses of users in your case you can use stream.get method you can found it here http://developers.facebook.com/docs/reference/rest/stream.get/
NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
[params setValue:[NSString stringWithFormat:@"%@", appDelegate.user_id] forKey:@"uid"];
[params setValue:@"150" forKey:@"limit"];
[params setValue:@"results" forKey:@"callback"];
[_facebook requestWithMethodName: @"status.get"
andParams: params
andHttpMethod: @"POST"
andDelegate: self];
You can use this code for you purpose.
Upvotes: 1