I have setup a login with Facebook button using the Facebook API a week ago and today I am unable to login or sign-up at all with Facebook. I constantly get the error message: One Take[49749:60b] Uh oh. The user cancelled the Facebook login.
Here is the code that handles signing up/login with Facebook.
- (IBAction)fbButtonPressed:(id)sender
{
NSArray *permissions =@[@"public_profile", @"email", @"user_friends"];
[PFFacebookUtils logInWithPermissions:permissions block:^(PFUser *user, NSError *error) {
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(@"User signed up and logged in through Facebook!");
FBRequest *request = [FBRequest requestForMe];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error){
NSDictionary *userData = (NSDictionary *)result;
NSLog(@"%@", userData);
NSString *facebookID= userData[@"ID"];
NSURL *pictureURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large&return_ssl_resources=1", facebookID]];
NSMutableDictionary *userProfile = [NSMutableDictionary dictionaryWithCapacity:7];
if (facebookID){
userProfile[@"facebookID"] = facebookID;
}
if (userData[@"name"]) {
user.username = userData[@"name"];
}
if (userData[@"email"]){
user.email = userData[@"email"];
}
/*
if ([pictureURL absoluteString]){
userProfile[@"pictureURL"] = [pictureURL absoluteString];
[user setObject:pictureURL forKey:@"profile_picture"];
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error){
NSLog(@"ERROR: %@ %@", error, [error userInfo]);
}
}];
}
[[PFUser currentUser] saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error){
NSLog(@"ERROR: %@ %@", error, [error userInfo]);
}else{
[self.navigationController popToRootViewControllerAnimated:YES];
}
}];
*/
}
}];
}];
}
The way that I have setup the App is that the HomeViewController is the first screen that is to be displayed and within the viewDidLoad and ViewDidAppear it checks to see if the user is a current user. THe reason for the code being in two places is because if I logout of the app and login again, it will assume the current user is the now logged out user and the app will now display information that should not necessarily be seen by the new user.
Here is the HomeViewController.
- (void)viewDidLoad
{
self.accepted = [NSMutableArray new];
self.currentUser = [PFUser currentUser];
[super viewDidLoad];
if ((self.currentUser = [PFUser currentUser])){
NSLog(@" Current User:%@", self.currentUser.username );
}else if ([PFUser currentUser] && [PFFacebookUtils isLinkedWithUser:[PFUser currentUser]]){
NSLog(@"current User: %@ is also linked W/FB!", self.currentUser.username);
}else{
[self performSegueWithIdentifier:@"showLogin" sender:self];
}
backgroundQueue = dispatch_queue_create("Word", NULL);
background2 = dispatch_queue_create("Hello", NULL);
}
-(void)viewWillAppear:(BOOL)animated
{
if (self.images == nil){
self.images = [[NSMutableArray alloc]init];
}
if ((self.currentUser = [PFUser currentUser])){
dispatch_async(backgroundQueue, ^{
PFQuery *messageQUery = [PFQuery queryWithClassName:@"Message"];
[messageQUery whereKey:@"recipientIds" equalTo:[[PFUser currentUser] objectId]];
[messageQUery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error){
NSLog(@"ERROR: %@, %@", error, [error userInfo]);
}else{
dispatch_async(dispatch_get_main_queue(), ^{
self.messages = objects;
[self.tableView reloadData];
NSLog(@"%@", self.messages);
});
}
}];
});
PFRelation *friendRelation = [self.currentUser relationForKey:@"friendRelation"];
PFQuery *acceptedQuery = [PFQuery queryWithClassName:@"FriendRequest"];
PFQuery *userQuery = [PFUser query];
//PFQuery *compoudQuery = [PFQuery orQueryWithSubqueries:@[acceptedQuery, userQuery]];
[acceptedQuery whereKey:@"status" equalTo:@"Accepted"];
[acceptedQuery whereKey:@"fromUser" equalTo:self.currentUser.objectId];
[userQuery whereKey:@"objectId" matchesKey:@"toUser" inQuery:acceptedQuery];
[userQuery whereKey:@"objectId" matchesKey:@"objectId" inQuery:acceptedQuery];
[userQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error){
NSLog(@" ERROR: %@ %@", error, [error userInfo]);
}else{
[self.accepted addObjectsFromArray:objects];
NSLog(@"%@" , objects);
[self.tableView reloadData];
for (PFUser *user in self.accepted){
[friendRelation addObject:user];
[self.accepted removeObject:user];
if (self.accepted.count == 0){
[self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error){
NSLog(@"ERROR: %@ %@", error, [error userInfo]);
}
}];
}
}
}
}];
}else{
[self performSegueWithIdentifier:@"showLogin" sender:self];
}
[super viewWillAppear:animated];
}
The homeViewController does more than just check the status of those using the app, but I did display the methods there that can potentially have an impact with the problem I am experiencing.
EDIT: running the Parse FB integration tutorial returns this error:
2014-05-20 23:36:18.852 IntegratingFacebookTutorial[179:60b] Uh oh. An error occurred: Error Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed. (com.facebook.sdk error 2.)" UserInfo=0x165ab770 {com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:SystemLoginCancelled, com.facebook.sdk:ErrorInnerErrorKey=Error Domain=com.apple.accounts Code=7 "The Facebook server could not fulfill this access request: Error validating access token: The session has been invalidated because the user has changed the password." UserInfo=0x165c1700 {NSLocalizedDescription=The Facebook server could not fulfill this access request: Error validating access token: The session has been invalidated because the user has changed the password.}, com.facebook.sdk:ErrorSessionKey=, expirationDate: (null), refreshDate: (null), attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(null)>}
I have recently had to change my FB name, but not my password.