Search code examples
iphoneiosfacebookios6

An active access token must be used to query information about the current user


I am trying to fetch user details but am currently unable to fetch images.This is the error I am getting:

{
    error =     {
        code = 2500;
        message = "An active access token must be used to query information about the current user.";
        type = OAuthException;
    };
}

This is my code:

   if(!self.store)
    {
        ACAccountStore *store1 = [[ACAccountStore alloc] init];
        self.store=store1;
        [store1 release];

    }

    ACAccountType *fbAccountType =
    [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    NSArray * permissions = @[@"read_stream", @"publish_stream",@"email", @"user_birthday",@"publish_actions",@"user_photos"];
    NSDictionary * dict = @{ACFacebookAppIdKey : @"my_key", ACFacebookPermissionsKey : permissions, ACFacebookAudienceKey : ACFacebookAudienceOnlyMe};
    //  Request permission from the user to access the available Twitter accounts
    [store requestAccessToAccountsWithType:fbAccountType options:dict completion:^(BOOL granted, NSError *error) {
        __block NSString * statusText = nil;
        if (granted) {
            statusText = @"Logged in";
            NSArray * accounts = [store accountsWithAccountType:fbAccountType];
            store = [accounts lastObject];
            account = [accounts objectAtIndex:0];
            NSLog(@"account is: %@", account);
            NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me?fields=picture"];
            SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                    requestMethod:SLRequestMethodGET
                                                              URL:requestURL
                                                       parameters:nil];
            request.account = account;
            [request performRequestWithHandler:^(NSData *data,
                                                 NSHTTPURLResponse *response,
                                                 NSError *error) {

                if(!error){
                    NSDictionary *list =[NSJSONSerialization JSONObjectWithData:data
                                                                        options:kNilOptions error:&error];
                    NSLog(@"Dictionary contains: %@", list );
                }
                else{
                    //handle error gracefully
                }

            }];
        }

If I use https://graph.facebook.com/me as url then it works fine. But I need the profile pic as well. What to do?


Solution

  • "fields" is a parameter, not a part of the URL itself. This works:

    SLRequest *videoLimitsRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                       requestMethod:SLRequestMethodGET
                                                                 URL:[NSURL URLWithString:@"https://graph.facebook.com/me"]
                                                          parameters:@{@"fields": @"video_upload_limits"}];
    

    FYI, token is added automatically when you attach account to the SLRequest.