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

When authenticating with the following authorization method, I get com.facebook.sdk error 5 using startWithGraphPath and startForMeWithCompletionHandler, but not with requestWithGraphPath. I successfully get a token (print in didLogin) and get everything I want with requestwithGraphPath, but I cannot work with other methods. If someone came across the same problem or something similar or have any idea, I would be glad if you share it.

thanks

Method:

NSArray *permissions = [[NSArray alloc] initWithObjects: @"user_likes",@"offline_access",@"read_stream",@"publish_stream",nil]; [_facebook authorize:permissions]; 
+4
source share
2 answers

The following solution worked for me. But if you save a permanent access token, you must be sure that the user does not delete the application’s rights, otherwise he will give an error. And you can check this with requestWithGraphPath → "me / permissions".

Application init function (e.g. :: didFinishLaunchingWithOptions / or, where you start your Facebook object, which should be fbsessiondelegate on average)

 ... 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 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"]); }]; 
+2
source

The StartWithGraphPath method and other start * methods probably do not collect the active session. These methods rely on the established active session. Cm:

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 need to do something like this:

 [FBSession setActiveSession:session]; 

If the session is an FBSession that you previously configured.

+10
source

Source: https://habr.com/ru/post/1447513/


All Articles