mercredi 25 février 2015

iOS Facebook SDK 3.23 request publish permission

I am trying to request the user @"publish_actions" permission for the active FBSession. After hours of researching online I found two approaches but both of them do not deliver the expected result : @"publish_actions in the session.permissions array.


First approach:



[FBSession openActiveSessionWithPublishPermissions:@[@"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
NSLog(@"---> %@", session.permissions);

}];


In this case the session.permissions does not contain @"publish_actions", the status is FBSessionStateOpen and the error is nil.


Second approach:



[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session1, FBSessionState status, NSError *error) {
if (session1.state == FBSessionStateOpen) {
// then ask for publishing permission
if (![session1.permissions containsObject:@"publish_actions"]) {
[FBSession.activeSession requestNewPublishPermissions:@[@"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *session2, NSError *error) {

NSLog(@"--> %@", session2.permissions);

if (error.fberrorCategory == FBErrorCategoryUserCancelled){
NSLog(@"User canceled?!");
}

}];

}else{
// permission already granted
}
}else{
// session not open
}
}];


In this second case, session2 is open, there is no @"publish_actions" within the permissions and the error category is FBErrorCategoryUserCancelled. The weird thing is that I haven't canceled the publish permission request and more strange, I haven seen that request inside the Facebook app. (it was a fast jump between my app and Facebook).


In this post on stackoverflow I read that I should put my publish permission request in a dispatch_async(dispatch_get_current_queue(), ^{}); block. I did that and still the same result: the error of the requestNewPublishPermissions:completionHandler: is : Error Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed. com.facebook.sdk:ErrorReauthorizeFailedReasonUserCancelled"


Any ideas on how I could get a hold of a session that has the @"publish_actions" permission?


Later edit: I tried also this approach and still, the error is the same.


Aucun commentaire:

Enregistrer un commentaire