0
- (IBAction)LoginViaFb:(id)sender {

 // Set permissions required from the facebook user account
    NSArray *permissionsArray = @[ @"user_email", @"user_relationships", @"user_birthday", @"user_location"];

    // Login PFUser using facebook
    [PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {

        NSLog(@"user=%@",user);

        if (!user) {
            if (!error) {
                NSLog(@"Uh oh. The user cancelled the Facebook login.");
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Log In Error" message:@"Uh oh. The user cancelled the Facebook login." delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Dismiss", nil];
                [alert show];
            } else {
                NSLog(@"Uh oh. An error occurred --- %@", error);
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Log In Error" message:[error description] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Dismiss", nil];
                [alert show];
            }
        } else if (user.isNew) {
            NSLog(@"User with facebook signed up and logged in!");
        } else {
            NSLog(@"User with facebook logged in!");
        }

        // If the user is already logged in, display any previously cached values before we get the latest from Facebook.
        if ([PFUser currentUser]) {
            [self updateProfile];
        }

        // Send request to Facebook
        FBRequest *request = [FBRequest requestForMe];
        [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
            // handle response
            if (!error) {
                // Parse the data received
                NSDictionary *userData = (NSDictionary *)result;
                NSLog(@"userData -------- %@",userData);

                NSString *facebookID = userData[@"id"];

                NSMutableDictionary *userProfile = [NSMutableDictionary dictionaryWithCapacity:7];

                if (facebookID) {
                    userProfile[@"facebookId"] = facebookID;
                }

                if (userData[@"name"]) {
                    userProfile[@"name"] = userData[@"name"];
                }

                if (userData[@"location"][@"name"]) {
                    userProfile[@"location"] = userData[@"location"][@"name"];
                }

                if (userData[@"gender"]) {
                    userProfile[@"gender"] = userData[@"gender"];
                }

                if (userData[@"birthday"]) {
                    userProfile[@"birthday"] = userData[@"birthday"];
                }

                if (userData[@"relationship_status"]) {
                    userProfile[@"relationship"] = userData[@"relationship_status"];
                }

                [[PFUser currentUser] setObject:userProfile forKey:@"profile"];
                [[PFUser currentUser] saveInBackground];

                [self updateProfile];
            } else if ([[[[error userInfo] objectForKey:@"error"] objectForKey:@"type"]
                        isEqualToString: @"OAuthException"]) { // Since the request failed, we can check if it was due to an invalid session
                NSLog(@"The facebook session was invalidated");

            } else {
                NSLog(@"Some other error: %@", error);
            }
        }];


    }];

After writing this code, my log shows:

  • user=(null)

  • Uh oh. An error occurred --- Error Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed. (com.facebook.sdk error 2.)" UserInfo=0xbf6f0c0 {com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:SystemLoginDisallowedWithoutError, com.facebook.sdk:ErrorSessionKey=, expirationDate: (null), refreshDate: (null), attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(null)>}

Please help, where i am doing mistake? and Thanks in advance.

Krunal
  • 6,440
  • 21
  • 91
  • 155
  • Are you sure that you have facebook sdk setup correctly for use with Parse SDK? Have you followed the Parse SDK docs for facebook login? – Gaurav Singh Nov 26 '13 at 09:46
  • yes, i have followed this sample project: https://www.dropbox.com/s/bu6oo8o877px0as/IntegratingFacebookTutorial-master.zip – Krunal Nov 26 '13 at 09:53
  • Have you tried this? https://www.parse.com/tutorials/integrating-facebook-in-ios I have used this tutorial to integrate Facebook SDK with Parse and it worked without any trouble. – Gaurav Singh Nov 26 '13 at 09:57
  • Dude, that what i am following but getting error – Krunal Nov 26 '13 at 10:06
  • check this link: http://stackoverflow.com/questions/15831610/the-operation-couldnt-be-completed-com-facebook-sdk-error-2-ios6 – Gaurav Singh Nov 26 '13 at 10:11

0 Answers0