对于userId,PFTwitterUtils logInWithBlock始终返回nil

PFTwitterUtils的logInWithBlock方法始终将userId返回为nil。 知道为什么会这样吗?

我使用的是parse.com版本:1.7.2

[PFTwitterUtils logInWithBlock:^(PFUser *user, NSError *error) { if (!user) { NSLog(@"Uh oh. The user cancelled the Twitter login."); return; } else if (user.isNew) { NSLog(@"User signed up and logged in with Twitter!"); if([PFTwitterUtils isLinkedWithUser:user]){ NSLog(@"userID %@", [PFTwitterUtils twitter].userId); } //... } else { NSLog(@"User logged in with Twitter!"); } }]; 

userId为nil的原因是该用户已经登录设备。 如果您在设备上进行了大量测试并忘记注销,则可能会发生这种情况。

如果您在尝试再次登录之前注销,那就没问题了。

所以这是一个测试的例子:

 [PFUser logOut]; [PFTwitterUtils logInWithBlock:^(PFUser *user, NSError *error) { if (!user) { NSLog(@"Uh oh. The user cancelled the Twitter login."); return; } else if (user.isNew) { NSLog(@"User signed up and logged in with Twitter!"); if([PFTwitterUtils isLinkedWithUser:user]){ NSLog(@"userID %@", [PFTwitterUtils twitter].userId); } //... } else { NSLog(@"User logged in with Twitter!"); } }];