Fbsession: an Attempt Was Made Reauthorize Permissions on an Unopened Session

FBSession: an attempt was made reauthorize permissions on an unopened session in ios

I think that you have to set to FBSession what is its active session :

FBSession *session = [[FBSession alloc] init];
[FBSession setActiveSession:session];

FBSession requestNewPublishPermissions fails before response

I found the solution to this problem on the answer to this question Facebook iOS 3.1 sdk login with publish permission callbacks

 dispatch_async(dispatch_get_current_queue(), ^{
[self openSessionForPublishPermissions];
});

Where opensessionforpublishpermissions is the method that contains the requestNewPublishPermissions method.

"The reason is that the call to reauthorize.. needs to be after the event loop of which openActiveSession.. is called."

I assume this is a bug in the Facebook SDK, it doesn't make sense for this to be normal behaviour and I haven't seen any of the Facebook docs comment on this being the expected behaviour.

When using Facebook Graph API getting an error - Session: an attempt was made to request new permissions for a session that has a pending request

Turns out, I wasn't passing the proper Permissions when making a Request. We set the Permissions like this -

request = new Session.OpenRequest(mActivity);
request.setDefaultAudience(...);
request.setLoginBehavior(...);
request.setPermissions(permission); // <-- This is where we need to specify the permissions.

session.openForPublish(request);

I do not know whether this is the proper solution, but it seems to work for me.

FBSession requestNewPublishPermissions how to handle Skip user action

same for me, seems like this is bug in Facebook SDK, but I am not sure. I have added additional check if session has new permissions.

    - (void)postToFacebookWithMessage:(NSString *)message completionBlock:(void (^)(NSError *))completionBlock
{
NSArray *permissions = @[@"publish_actions"];

void (^completionHandler)(FBSession *session, NSError *error) = ^(FBSession *session, NSError *error) {
if (error != nil)
{
if (completionBlock != nil)
{
completionBlock(error);
}
}
else if(![self activeSessionHasPermissions:permissions])
{
NSError *error = [NSError errorWithDomain:@"Facebook" code:FBAccessDisabledCode userInfo:@{NSLocalizedDescriptionKey:NSLocalizedString(@"Facebook access disabled", @"Facebook access disabled")}];
if (completionBlock != nil)
{
completionBlock(error);
}
}
else
{
NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
action[@"message"] = message;

[FBRequestConnection startForPostWithGraphPath:@"me/og.posts" graphObject:action completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
// internal error 1611231 means that this was already posted
if (error.code == 5)
{
error = [NSError errorWithDomain:@"Facebook" code:FBDuplicateActionErrorCode userInfo:@{NSLocalizedDescriptionKey:NSLocalizedString(@"Already posted to Facebook", @"Already posted to Facebook")}];
}

if (completionBlock != nil)
{
completionBlock(error);
}
}];
}
};

if ([self activeSessionHasPermissions:permissions])
{
completionHandler([FBSession activeSession], nil);
}
else
{
[[FBSession activeSession] requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone completionHandler:completionHandler];
}
}

- (BOOL)activeSessionHasPermissions:(NSArray *)permissions
{
__block BOOL hasPermissions = YES;
for (NSString *permission in permissions)
{
NSInteger index = [[FBSession activeSession].permissions indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isEqualToString:permission])
{
*stop = YES;
}
return *stop;
}];

if (index == NSNotFound)
{
hasPermissions = NO;
}
}
return hasPermissions;
}

hope this will help

cannot open session or publish post to facebook

This was temporarily fixed, and I actually no longer recall what the actual issue was...but I now use parse facebook utils v4 and facebook sdk 4.0+ and the issue no longer exists because there is no such thing as sessions anymore.

How do I cancel a previous Facebook reauthorize call?

From your App's delegate, when - (void)applicationDidBecomeActive:(UIApplication*)application is invoked, you need to make a call to the active session's handleDidBecomeActive method. Once you do that, the completion handler associated with your reauthorizeWithPublishPermissions call will be invoked, and will provide the appropriate error.

- (void)applicationDidBecomeActive:(UIApplication*)application
{
[[FBSession activeSession] handleDidBecomeActive];
}


Related Topics



Leave a reply



Submit