I am not able to fetch user data from Facebook in iOS

前端 未结 2 1697
梦毁少年i
梦毁少年i 2021-01-15 22:02

I am new to iPhone programming.Using below code i am login into Facebook and fetching data.But here problem is if click on the Loginwithfacebook button Facebook dialog box o

2条回答
  •  一生所求
    2021-01-15 22:42

    If you are willing to, you can also do it with Parse :

    - (IBAction)facebookRegistrationButtonPressed {
    
            // The permissions requested from the user
    
            NSArray *permissionsArray = @[@"email", @"user_about_me", @"publish_actions", @"status_update", @"manage_pages", @"publish_stream"];
    
            // Login PFUser using Facebook
            [PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
                if (!user) {
                    if (!error) {
                        NSLog(@"Uh oh. The user cancelled the Facebook login.");
                    } else {
                        NSLog(@"Uh oh. An error occurred: %@", error);
                    }
                } else if (user.isNew) {
                    NSLog(@"User with facebook signed up and logged in!");
                    [self processFacebookRequest];
                } else {
                    NSLog(@"User with facebook logged in!");
                    [self processFacebookRequest];
                }
            }];
        }
    
        - (void)processFacebookRequest {
            FBRequest *request = [FBRequest requestForMe];
            // Send request to Facebook
            [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                if (!error) {
                    // result is a dictionary with the user's Facebook data
                    NSDictionary *userData = (NSDictionary *)result;
                    NSString * email = [result objectForKey:@"email"];
    
                    NSString *facebookID = userData[@"id"];
                    NSLog(@"facebookID = %@", facebookID);
    
                } else {
                    NSLog(@"error : %@", error.localizedDescription);
                }
            }];
        }
    

提交回复
热议问题