Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying Facebook user data through new iOS6 social framework

Tags:

facebook

ios6

I am trying to query information about a user using iOS 6's new Facebook integration API. This is the code I'm using, which is basically identical to what they demoed at WWDC:

{
NSDictionary *parameters = @{};
NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/me"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                        requestMethod:SLRequestMethodGET
                                                  URL:url
                                           parameters:parameters];
request.account = self.account;
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
    NSLog(@"Facebook request received, status code %d", urlResponse.statusCode);
    NSString *response = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    NSLog(@"Response data: %@", response);
    dispatch_async(dispatch_get_main_queue(), ^{

    });
}];
}

Problem is I am getting error code 2500 from Facebook: "An active access token must be used to query information about the current user." If I change the query to https://graph.facebook.com/[facebook id] then it works fine. I am assuming the problem is that iOS is passing the access token of the app instead of the user's access token when sending the request via requestForServiceType. I just don't know how to fix it. Obviously anticipating and hardcoding the Facebook IDs of my users is not an option. Any suggestions?

like image 691
Kevin Reynolds Avatar asked Jun 30 '12 01:06

Kevin Reynolds


1 Answers

add your active access token in paramete like

NSDictionary *parameters = [NSDictionary dictionaryWithObject:@"PUT_ACCESS_TOKEN_HERE" forKey:@"access_token"];
like image 135
Sunil_Vaishnav Avatar answered Nov 16 '22 01:11

Sunil_Vaishnav