Reputation:
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
Upvotes: 0
Views: 1091
Reputation: 663
Go to the app on facebook and then check if there is an orange icon with the following text This app is in Sandbox Mode. In that case, what you need to do, is testing the login functionality using an email that be in the developers group with develop permissions.
In other case, click on "edit app" and then add the bundleId that you're using in the xcode project. to see it you can go to .plist file or make add the following code to print it on the console.
NSLog(@"%@",[[NSBundle mainBundle] bundleIdentifier]);
Upvotes: 0
Reputation: 11026
You have to make sure that sandbox is enabled in your Facebook app id.
Upvotes: 0