0

Edit: No work around yet, but Facebook in there own SDK seemed to have deprecated using the system FB sign-on. I tried the latest SDK, and it just completely ignores the system sign-on. Unfortunately I can' used the latest SDK as, despite using the "legacy" setting, it still returns a token which doesn't give me what I need. It might be useful to see how they're bypassing the system settings though!

Original Q

I have an app which is using Facebook to authenticate.

I'm using the Facebook SDK (3.13.1 - the last pre api v2 version)

If I attempt to authenticate, as long as I don't have a FB account setup in the system settings, everything works fine. The app launches either the FB mobile app or mobile Safari to login an prompts me to grant the necessary permissions.

As soon as there is a system account setup, it fails silently. I'm deleting the app in between runs to ensure that the lack of permissions isn't persisting. If I run some of the FB sample apps which come with the SDK, they prompt for permission just fine, so it is obviously a problem with my app or the configuration of the Facebook app.

I've looked at these 2 similar questions:

Facebook Login - If user account is present (and app is not installed) login fails

Facebook Login error when facebook account is already configured in system preferences

but neither provides an answer that works in my situation. (E.g I do have bundle identifiers configured in the Facebook App)

I've tried using my own custom login code (based on the Facebook guide) and using the FBLoginView, both with the same effect.

I've also tried using ACAccountStore to make the request directly to the system store, with the same effect. Any ideas?

I'll include some code, but I'm fairly certain the code is not the problem - it all works fine if the system FB account is not configured: (i've changed my FacebookAppIDkey here)

ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = @{  ACFacebookAppIdKey: @"123",
                            ACFacebookPermissionsKey: @[@"public_profile", @"user_likes", @"user_friends", @"email"],
                            ACFacebookAudienceKey: ACFacebookAudienceFriends};

[accountStore requestAccessToAccountsWithType:facebookType options:options completion:^(BOOL granted, NSError *error) {
    if (granted) {
        NSArray *accounts = [accountStore
                accountsWithAccountType:facebookType];
        id facebookAccount = [accounts lastObject];
        DLog(@"%@", facebookAccount);
    }
    else
    {
        if (error)
        {
            DLog(@"%@", error.localizedDescription);
        }
    }
}];

Using the SDK:

[FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"user_likes", @"user_friends", @"email"]
                                       allowLoginUI:YES
                                  completionHandler:
                                          ^(FBSession *session, FBSessionState state, NSError *error) {

                                              AppDelegate* appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
                                              [appDelegate sessionStateChanged:session state:state error:error];
                                              if ([FBSession activeSession].isOpen) {
                                                  __typeof__(self) strongSelf = weakSelf;
                                                  strongSelf.facebookToken = session.accessTokenData.accessToken;
                                                  [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
                                                  {
                                                      completion(error,(NSDictionary *)result);
                                                  }];
                                              } else {
                                                  completion(error,nil);
                                              }

                                          }];
Community
  • 1
  • 1
Matt
  • 435
  • 5
  • 15

1 Answers1

0

The problem may is because you are already logged in but doesn't have an access token. So you have to check the condition if(appDelegate.session.state == FBSessionStateCreatedTokenLoaded) .

Hope the following code will help.

VNSAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];




if (!appDelegate.session.isOpen) {
    // create a fresh session object
    appDelegate.session = [[FBSession alloc] init];

    // if we don't have a cached token, a call to open here would cause UX for login to
    // occur; we don't want that to happen unless the user clicks the login button, and so
    // we check here to make sure we have a token before calling open
    if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {
        // even though we had a cached token, we need to login to make the session usable

        [[appDelegate.session initWithPermissions:appDelegate.permissions]openWithCompletionHandler:^(FBSession *session,
                                                         FBSessionState status,
                                                         NSError *error) {
            // we recurse here, in order to update buttons and labels
            [self updateView];
        }];

    }
JIthin
  • 1,413
  • 1
  • 13
  • 29
  • I don't think that explains why the built in ACAccountStore stuff is not working either, when not making any use of the FB SDK at all... – Matt Jun 19 '14 at 08:05
  • Are you using the actual FacebookAppidkey created by you or just @"123" as in the code shows? – JIthin Jun 19 '14 at 09:15
  • As mentioned in the original post, I've changed it for here :-) – Matt Jun 19 '14 at 11:56