Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not getting call to loginViewShowingLoggedInUser from FBLoginView

Tags:

ios

facebook

I am using the Facebook SDK for the first time. I am working with Xcode 5.1 and iOS 7.

I programmatically display FBLoginView:

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"viewDidLoad");

    // Do any additional setup after loading the view.

    if ( !loginView ) {
       // loginView =[[FBLoginView alloc] initWithReadPermissions:@[@"basic_info"]];
        loginView =[[FBLoginView alloc] initWithReadPermissions:[NSArray arrayWithObjects:@"basic_info", @"user_location", nil]];
    }
    loginView.delegate = self;

    loginView.frame = CGRectOffset(loginView.frame,
                    (self.view.center.x -(loginView.frame.size.width /2)), 5);
    CGPoint vCenter   = CGPointMake( CGRectGetMidX(self.view.frame),
                                   CGRectGetMidY(self.view.frame) );
    CGPoint lvCenter  = CGPointMake( vCenter.x, vCenter.y+100.0 );
    loginView.center = lvCenter;
    [self.view addSubview:loginView];

    [self updateView];
}

I have implemented the required override functions:

#pragma mark - FBLoginViewDelegate

- (void) loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user {
    NSLog(@"loginViewFetchedUserInfo");

     [self updateView];

}
- (void) loginViewShowingLoggedInUser:(FBLoginView *)loginView {
    NSLog(@"loginViewShowingLoggedInUser");

    [self updateView];

}
- (void) loginViewShowingLoggedOutUser:(FBLoginView *)loginView {
    NSLog(@"loginViewShowingLoggedOutUser");

     [self updateView];
}

- (void)updateView {
    NSLog(@"FB updateView");
    [[FBRequest requestForMe] startWithCompletionHandler:
     ^(FBRequestConnection *connection, NSDictionary<FBGraphUser>*FBUser, NSError *error) {
         if (error) {
             NSLog(@"updateView - error");
         } else {
             NSLog(@"updateView - good");
             NSNumber    *owner_id  = [NSNumber numberWithLong:[[FBUser id] longLongValue]];
             if ( FB_user_id == nil ) {
                 FB_user_id = owner_id;
                 NSLog(@"FBUser ID  = %@", FB_user_id);

                 loggedInSession = [FBSession activeSession];
                 [[NSUserDefaults standardUserDefaults] setObject:[FBUser id] forKey:@"eventOwnerID"];
                 [self performSegueWithIdentifier:@"continue_to_app" sender:self];
             }
         }
     }];
    if ([self checkFacebookSession]) {
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.view setNeedsDisplay];
    });
}

The FBLoginView button appears with "Log in with Facebook". I can log in and accept permissions, but the loginViewShowingLoggedInUser override function never gets called.

Someone suggested adding the following:

- (BOOL) application:(UIApplication *) application 
                openURL:(NSURL *)url 
                sourceApplication:(NSString *)sourceApplication 
                annotation:(id)annotation 
{
    NSLog ( @"application openURL");
    NSLog ( @"URL = %@", url);
    NSLog ( @"Application = %@", sourceApplication);
    // Call FBAppCall's ha
    BOOL wasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
    //[LoginUIViewController updateView];

    return wasHandled;
}

This code had no effect and was never executed.

What am I doing wrong?

like image 319
user3147421 Avatar asked May 06 '14 18:05

user3147421


2 Answers

  1. You are using @"basic_info", for this Facebook shows following error when I tried testing your code!

    Invalid Scope: basic_info. Use public_profile, user_friends instead
    
  2. I was interested in knowing where did you add the method:

    - (BOOL) application:(UIApplication *) application 
                 openURL:(NSURL *)url 
       sourceApplication:(NSString *)sourceApplication 
              annotation:(id)annotation 
    {
        NSLog ( @"application openURL");
        NSLog ( @"URL = %@", url);
        NSLog ( @"Application = %@", sourceApplication);
        // Call FBAppCall's ha
        BOOL wasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
        //[LoginUIViewController updateView];
    
        return wasHandled;
    }
    

It should be in your AppDelegate, which works for me.

like image 194
Vivek Molkar Avatar answered Oct 11 '22 23:10

Vivek Molkar


The read permissions have changed. Refer this : [https://developers.facebook.com/docs/apps/changelog#v2_0_permissions ][1]

The Error "invalide scope : basic info use public_profile, user friends instead" clearly states that "basic_info" is invalid and it suggests to make use of "public_profile" or "user_friends" as the new scope.

Change it in the following code:

    self.loginView.readPermissions = @[@"basic_info"];

TO

    self.loginView.readPermissions = @[@"public_profile"];
like image 21
taus-iDeveloper Avatar answered Oct 12 '22 00:10

taus-iDeveloper