使用Facebook登录按钮返回错误

时间:2014-05-21 00:04:24

标签: ios facebook-graph-api parse-platform facebook-app-requests

我在一周前使用Facebook API设置了使用Facebook按钮登录,今天我无法登录或注册Facebook。我经常收到错误信息:One Take [49749:60b]哦哦。用户取消了Facebook登录。

以下是处理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];
                        }
                    }];

            */

                }
            }];

    }];

}

我设置应用程序的方式是HomeViewController是第一个要显示的屏幕,在viewDidLoad和ViewDidAppear中,它会检查用户是否是当前用户。代码在两个地方的原因是因为如果我退出应用程序并再次登录,它将假定当前用户是现在已注销的用户,并且应用程序现在将显示新用户不一定会看到的信息。

这是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];



}

homeViewController不只是检查使用该应用程序的人的状态,但我确实显示了那些可能会对我遇到的问题产生影响的方法。

编辑:运行Parse FB集成教程会返回以下错误:

2014-05-20 23:36:18.852 IntegratingFacebookTutorial [179:60b]哦哦。发生错误:Error Domain = com.facebook.sdk Code = 2“无法完成操作。(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“Facebook服务器无法满足此访问请求:验证访问令牌时出错:会话已失效,因为用户已更改密码。” UserInfo = 0x165c1700 {NSLocalizedDescription = Facebook服务器无法满足此访问请求:验证访问令牌时出错:会话已失效,因为用户已更改密码。},com.facebook.sdk:ErrorSessionKey =,expirationDate:(null) ,refreshDate:(null),attemptsRefreshDate:0001-12-30 00:00:00 +0000,permissions:(null)>}

我最近不得不更改我的FB名称,但不是我的密码。

0 个答案:

没有答案