FBSDKLoginManager logInWithPublishPermissions always returns isCancelled=YES

facebook login is not working in ios 13
fbsdkloginmanager has been renamed to loginmanager
facebook login permissions ios
facebook login integration in ios objective-c
failed for url: fbauth2
specify facebook app id in info plist
ios facebook login without leaving app
facebook integration in ios

I am having trouble figuring out how to log a user into my app. [FBSDKAccessToken currentAccessToken] is nil, so I am calling:

[[[FBSDKLoginManager alloc] init] logInWithPublishPermissions:@[@"publish_actions"] handler:…];

as per the included sample project. This switches to the Facebook app, but the message says "You have already authorized App Name.". I click OK and it goes back into the app, but grantedPermissions and declinedPermissions are both nil on the result, and isCancelled is YES. [FBSDKAccessToken currentAccessToken] is still nil.

I can't figure out how I'm supposed to get currentAccessToken to be filled in. It seems to me the call to logInWithPublishPermissions should do that, but it isn't.

You should try adding in your AppDelegate didFinishLaunchingWithOptions :

return [[FBSDKApplicationDelegate sharedInstance] application:application
                                    didFinishLaunchingWithOptions:launchOptions];

This would get u [FBSDKAccessToken currentAccessToken] when user is logged in.

and

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                          openURL:url
                                                sourceApplication:sourceApplication
                                                       annotation:annotation];
}

If this method is not present into AppDelegate then it results into cancelled state.

Refer to : https://developers.facebook.com/docs/ios/getting-started#startcoding

Login always cancel iOS 13 Xcode 11 Beta 3 · Issue #482 , FBSDKLoginManager logInWithPublishPermissions always returns result,​isCancelled=YES on iOS 13.0. 2019-09-30 14:10 Ajith Kumar imported from  29 FBSDKLoginManager logInWithPublishPermissions always returns isCancelled=YES May 5 '15 28 Since iOS 7 SDK, UIButton suddenly becomes dark when highlighted Oct 3 '13 27 UITableView - scroll to the top Aug 13 '14

This can happen when your Facebook App doesn't have "publish_actions" permission, or you're not using a test user.

On Facebook, go to manage your app, then make sure that the Facebook user you're using is defined under "Roles" as an admin or tester.

If it's not a test user or admin - Facebook will require "publish_actions" permission to be reviewed and approved before allowing your app to use it, until then you'll receive a "isCancelled=YES" result.

After testing your app with this permission, it is possible to submit this permission for review, you'll need to upload a binary that demonstrates usage of this permission with exact details on how to use it. After it's approved, you'll be able to use it with non-test Facebook users.

fbsdkloginkit - St4k, Login always return cancel in the console, the error is nil isCancelled { print("​Cancelled \(error? in logInWithBehavior function in FBSDKLoginManager.m defined in Yes. It happens on ios 12 simulator now, not 13. 29 FBSDKLoginManager logInWithPublishPermissions always returns isCancelled=YES 28 Since iOS 7 SDK, UIButton suddenly becomes dark when highlighted 27 UITableView - scroll to the top

Since FBSDKLoginKit 4.6.0, the logInWithReadPermissions and logInWithPublishPermissions methods of FBSDKLoginManager seems to have additional fromViewController argument and use that to present modals.

I was calling logInWithPublishPermissions inside the callback of logInWithReadPermissions, which at that point the modal is not fully dismissed yet. (I know it's a bad practice to ask permission when it's not needed, but in my case this seems to be the right place to do.) This cause it to fail with isCancelled equals to YES. I added some delay and wait for the modal to be fully dismissed fixed the problem.

FBSDKLoginManager logInWithPublishPermissions always returns isCancelled=​YES. I am having trouble figuring out how to log a user into my  FBSDKLoginManager works directly with [FBSDKAccessToken currentAccessToken] and sets the "currentAccessToken" upon successful authorizations (or sets nil in case of logOut). You should check [FBSDKAccessToken currentAccessToken] before calling logIn* to see if there is a cached token available (typically in your viewDidLoad).

I had the same problem when I landed here, turns out I was only using the deprecated application openURL method because i was using google sign in too. To support iOS 8 and before you have to implement both the current and the deprecated method:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    return GIDSignIn.sharedInstance().handle(url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String!, annotation: options[UIApplicationOpenURLOptionsKey.annotation]) || FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
    return GIDSignIn.sharedInstance().handle(url, sourceApplication: sourceApplication, annotation: annotation) || FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}

The deprecated is the second.

Note: The FBSDK method is added after the google one with an or "||" operator but the order doesn't matter and if you wanna only use facebook method just erase the method and the or operator.

Note 2: As swift 3 still stabilizing the method name can change I suggest you always use the auto complete from XCode when overriding and implementing a delegate's method.

Hope this Helps o/

FB.LogInWithPublishPermissions Prompts the user to authorize your application for publish permissions using the Login Dialog appropriate to the platform. If the user is already logged in and has authorized your application, checks whether all permissions in the permissions parameter have been granted, and if not, prompts the user for any that are newly requested.

This method works in iOS 9

// Facebook Login Completion delegate
- (void)loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result error:(NSError *)error
{
    if (result){
        NSLog(@"%@",result);
        NSLog(@"%@",result.grantedPermissions);
       [self getFacebookData:result];
     }
}  

- (void)getFacebookData:(FBSDKLoginManagerLoginResult *)result{

   if (![result.grantedPermissions containsObject:@"email"])
   {
      FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
      login.loginBehavior = FBSDKLoginBehaviorWeb;
      [login logInWithReadPermissions:@[@"email"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
       {
         if (error)
         {
             // Process error
         }
         else if (result.isCancelled)
         {
             // Handle cancellations
         }
         else
         {
             if ([result.grantedPermissions containsObject:@"email"])
             {
                 NSLog(@"result is:%@",result);
                 if ([FBSDKAccessToken currentAccessToken]) {
                     [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"first_name, last_name, email, id"}]
                      startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                          if (!error) {
                              NSLog(@"fetched user:%@", result);
                              [self registerWithFacebook:result];
                          }else{
                              NSLog(@"%@",error);
                          }
                      }];
                 }


             }
         }
     }];


 }else{
    if ([FBSDKAccessToken currentAccessToken]) {
        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"first_name, last_name, email, id"}]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error) {
                 NSLog(@"fetched user:%@", result);
                 [self registerWithFacebook:result];
             }else{
                 NSLog(@"%@",error);
             }
         }];
    }
}

}

NOTE : Use FBSDKLoginBehaviorWeb instead of FBSDKLoginBehaviorBrowser. This will surely work

GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Sign up Login always cancel iOS 13 Xcode 11 Beta 3 #482

29 FBSDKLoginManager logInWithPublishPermissions always returns isCancelled=YES 28 Since iOS 7 SDK, UIButton suddenly becomes dark when highlighted 27 UITableView - scroll to the top

logInWithPublishPermissions(Fragment, Collection) Logs the user in with the requested publish permissions. public void logInWithPublishPermissions( Fragment fragment , Collection permissions )

Facebook Login with iOS SDK 4.0 in Swift. GitHub Gist: instantly share code, notes, and snippets.

Comments
  • Thanks! I must have missed those calls somehow.
  • @Dheeraj Singh : You saved my day brother. :)
  • i had done both the thing and still i am getting result.cancelled = true
  • Wow, this was the solution. So much time to understand why I always get iscancelled = YES... MANY thanks Kof.
  • This was also the solution for me. I had done all that other stuff but was on a different device that was logged into a different account that wasn't a test user.
  • I added publish_actions when calling FBSDKLoginManager().logInWithPublishPermissions() but it is still not working :(
  • If you only need public_profile read permission, you can just ask for publish permissions without having read permissions in advance. The SDK will handle it by itself by first asking the user for public_profile, then the write permissions you requested. This saves you from handling the dialog flow by yourself.