I just figured out how to properly request information from Facebook with the new iOS 6 accounts framework. My problem now is even after I renewed credentials, Facebook still tells me that I don't have access. I guess my last (working) token expired and now I can't get a new one. All accounts (tw + fb) should be set up correctly. Also the renewResult is ACAccountCredentialRenewResultFailed, which can be about anything...
Here is my code:
- (void)performSocialRequest:(SLRequest *)request completion:(void (^)(NSDictionary *responseDict))completion{
__block NSDictionary *accountInfo;
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if ([request.account.accountType.identifier isEqualToString:ACAccountTypeIdentifierTwitter]) {
accountInfo = [[NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error]lastObject];
completion(accountInfo);
} else {
accountInfo = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
if ([accountInfo objectForKey:@"error"]) {
[self.accountStore renewCredentialsForAccount:request.account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) {
if (renewResult == ACAccountCredentialRenewResultRenewed) {
NSLog(@"renewal succesful");
[request performRequestWithHandler:^(NSData *responseData2, NSHTTPURLResponse *urlResponse, NSError *error) {
completion([NSJSONSerialization JSONObjectWithData:responseData2 options:kNilOptions error:&error]);
}];
} else if (renewResult == ACAccountCredentialRenewResultRejected) {
NSLog(@"rejected");
completion(accountInfo);
} else if (renewResult == ACAccountCredentialRenewResultFailed){
NSLog(@"unknown (error: %@)", error);
completion(accountInfo);
}
}];
} else {
completion(accountInfo);
}
}
}];
}
The answer I get from the Facebook servers is always the same:
{
error = {
code = 2500;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
}
Hope you guys have some ideas, thanks in advance...
Dario