I'm having trouble logging in with publish permissions in the facebook 3.1 ios sdk.
My app has a button to share a video, and when the user clicks it I want to add the basic + publish permission. As I understand, i have to do two calls -
openActiveSessionWithReadPermissions
, and thenreauthorizeWithPublishPermissions
Here's the code I'm using now:
//Opens a Facebook session and optionally shows the login UX.
- (void)openSessionForReadPermissions
{
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
//this is called even from the reauthorizeWithPublishPermissions
if (state == FBSessionStateOpen && !error)
{
[self openSessionForPublishPermissions];
}
else if (state == FBSessionStateClosedLoginFailed)
{
[FBSession.activeSession closeAndClearTokenInformation];
[[NSNotificationCenter defaultCenter] postNotificationName:FBLoginErrorNotification object:session];
}
}];
}
-(void)openSessionForPublishPermissions
{
NSArray* permissions = [NSArray arrayWithObject:@"publish_stream"];
[[FBSession activeSession] reauthorizeWithPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:
^(FBSession *session, NSError *error)
{
if (!error)
{
[[NSNotificationCenter defaultCenter]
postNotificationName:FBLoginSuccessNotification
object:session];
}
else
{
[[NSNotificationCenter defaultCenter]
postNotificationName:FBLoginErrorNotification
object:session];
}
}];
}
I see that the block in the openSessionForReadPermissions is called twice (once with FBSessionStateOpen and once with FBSessionStateOpenTokenExtended from the openSessionForPublishPermissions call), and I get a ErrorReauthorizeFailedReasonUserCancelled when first trying to login to the app (if O deleted all app permissions before).
What is the proper way to implement this login? The app does not require Facebook log-in, except for this one feature, so the login process should be on the same button push.
Thanks!