FBSDKGraphRequest not working (iOS)

I am trying to use FBSDKGraphRequest inside a block of code that executes when a Facebook login button is clicked. However, for some reason, this piece of code is never executed. What could be the reason. The button I use is FBSDKLoginButton and it works fine. I just want to get user information, such as name and email address, after logging in.

[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"email,name"}]
                  startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                      NSLog(@"test");
                      if (!error) {
                          NSLog(@"fetched user:%@  and Email : %@", result,result[@"email"]);
                      }
                  }];
+4
source share
1 answer

Facebook, Facebook FBSDKLoginButton. . Facebook .

- (IBAction)FacebookLogin:(id)sender {
    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    [login
     logInWithReadPermissions: @[@"public_profile", @"email", @"user_friends"]
     fromViewController:self
     handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
         if (error) {
             NSLog(@"Process error");
         } else if (result.isCancelled) {
             NSLog(@"Cancelled");
         } else {
             NSLog(@"Logged in");

             [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"email,name"}]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error) {
                 NSLog(@"fetched user:%@  and Email : %@", result,result[@"email"]);
             }
         }];
         }
     }];
}
+2

Source: https://habr.com/ru/post/1610981/


All Articles