user1802694
user1802694

Reputation:

Facebook SDK 3.1 - com.facebook.sdk Error 5 when authenticating with [facebook authorize:permissions]

When authenticating with following authorization method i'm getting com.facebook.sdk error 5 with startWithGraphPath and startForMeWithCompletionHandler but not with requestWithGraphPath. I'm succesfully getting token (printing in didLogin) and getting anything which i want with requestwithGraphPath but i'm unable to get work with other methods. If anybody encountered with same issue or something similar or has any idea, i'd be happy if you share it.

Thanks

Method:

NSArray *permissions = [[NSArray alloc] initWithObjects: @"user_likes",@"offline_access",@"read_stream",@"publish_stream",nil];
[_facebook authorize:permissions];

Upvotes: 4

Views: 11226

Answers (2)

user1802694
user1802694

Reputation:

Following solution worked for me. But if you're storing a permanent access token, you need to be sure user not removed application permissions otherwise it will give an error. And you can check that with requestWithGraphPath -> "me/permissions".

Application Init Function (e.g.:didFinishLaunchingWithOptions/or where you init your Facebook object which needs to be fbsessiondelegate in the mean time)

...    
NSArray* permissions = [[NSArray alloc] initWithObjects:@"user_likes",@"offline_access", nil];

        FBSession*oursession = [[FBSession alloc] initWithPermissions:permissions];
...

FBDidLogin function:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];

Example graph api request function:

NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
        NSString *key = [userDefaults stringForKey:@"FBAccessTokenKey"];

    FBRequest* ourcon = [[FBRequest alloc] initWithSession:oursession graphPath:@"me/likes" parameters:params HTTPMethod:@"GET"];

            [ourcon startWithCompletionHandler: ^(FBRequestConnection *connection, id<FBGraphUser> result, NSError *error){
                if(error)
                {
                    //NSLog(error.code);
                    return;
                }

                NSArray* collection = (NSArray*)[result data];
                NSLog(@"You have %d like", [collection count]);

                NSDictionary* name = [collection objectAtIndex:14];
                NSLog(@"Like Name: %@", [name objectForKey:@"name"]);
            }];

Upvotes: 2

C Abernathy
C Abernathy

Reputation: 5523

The startWithGraphPath and other start* methods are likely not picking up an active session. Those methods are relying on an active session being set. See:

https://developers.facebook.com/docs/reference/ios/3.1/class/FBRequestConnection#startWithGraphPath%3AcompletionHandler%3A

"The request uses the active session represented by [FBSession activeSession]."

So you'll have to do something like this:

[FBSession setActiveSession:session];

Where session is an FBSession that you had previously set up.

Upvotes: 9

Related Questions