Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

in my iOS app, we have our user log-in using facebook to grab some of their information. I've included the code below that occurs when the users presses the button that reads "Log in with Facebook":

- (IBAction)toQuadAction:(id)sender {

// Query to fetch the users name and picture
NSString *query = @"SELECT name, username FROM user WHERE uid=me() ";

// Set up the query parameter
NSDictionary *queryParam = [NSDictionary dictionaryWithObjectsAndKeys:query, @"q", nil];
// Make the API request that uses FQL
[FBRequestConnection startWithGraphPath:@"/fql" parameters:queryParam HTTPMethod:@"GET"
                      completionHandler:^(FBRequestConnection *connection,
                                          id result,
                                          NSError *error) {
                          if (error) {
                              NSLog(@"Error: %@", [error localizedDescription]);
                          } else {
                              NSLog(@"My name: %@", result[@"data"][0][@"name"]);
                              NSLog(@"My username: %@", result[@"data"][0][@"username"]);


                              //SAVE TO CORE DATA
                              AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
                              NSEntityDescription *user = [NSEntityDescription entityForName:@"User" inManagedObjectContext:appDelegate.managedObjectContext];
                              NSFetchRequest *getName = [[NSFetchRequest alloc] init];
                              [getName setReturnsObjectsAsFaults:NO];
                              [getName setEntity:user];
                              NSError *error;
                              NSMutableArray *currentUser = [[appDelegate.managedObjectContext executeFetchRequest:getName error:&error] mutableCopy];

                              //SAVE THE NAME TO CORE DATA
                              [currentUser[0] setName:result[@"data"][0][@"name"]];


                              //SAVE NAME AND PICTURE TO PARSE
                              PFQuery *query = [PFQuery queryWithClassName:@"Student"];
                              [query whereKey:@"email" equalTo:[currentUser[0] valueForKey:@"email"]];
                              [query getFirstObjectInBackgroundWithBlock:^(PFObject *users, NSError *error) {
                                  if (!users){
                                      NSLog(@"The first object request failed");
                                  } else{
                                      NSLog(@"grabbed the object");
                                      //SET THE NAME IN PARSE
                                      [users setObject:result[@"data"][0][@"name"] forKey:@"name"];
                                      //SET THE IMAGE IN PARSE
                                      NSString *URLString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?width=235&height=385", result[@"data"][0][@"username"]];
                                      NSURL *picURL = [NSURL URLWithString:URLString];
                                      NSData *picData = [NSData dataWithContentsOfURL:picURL];
                                      PFFile *picture = [PFFile fileWithData:picData ];
                                      [users setObject:picture forKey:@"picture"];
                                      [users saveInBackground];
                                  }
                              }];
                          }
                          [self performSegueWithIdentifier:@"facebookToQuad" sender:sender];
                      }];
}

When I do this with a new user (in the iOS simulator), that has not already allowed my app on Facebook, I get an alert that says "The operation couldn't be completed. (com.facebook.sdk error 2.)".

I have seen this questions asked before, but I have not found a solution that fits me. For one, I am building native, not using PhoneGap or anything like that. Another thing, my internet connection seems fine. I don't have issues doing anything else.

Does anyone know of a solution to this issue? Thanks

share|improve this question
make sure that sandbox is disabled in fb id. – Parser 12 mins ago
Are all of your app url callback settings configured? – Wain 10 mins ago
add comment (requires an account with 50 reputation)

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.