我是整合Facebook的新手。到目前为止,我已经实现了登录。我一直在我们的数据库中保存用户ID,作为一种在登录时识别它们的方法。但是我今天注意到id改变了。如果id发生变化,我可以用什么来识别facebook用户?
以下是我正在使用的代码,g_fb_id是传递给我们服务器的ID。
// This method will handle ALL the session state changes in the app
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error
{
// If the session was opened successfully
if (!error && state == FBSessionStateOpen){
NSLog(@"Session opened");
// get facebook ID
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (! error) {
g_fb_id = [user objectForKey:@"id"];
g_user.birthday=user.birthday;
g_user.fb_page=[user objectForKey:@"link"];
g_user.first_name=user.first_name;
g_user.last_name=user.last_name;
g_user.email=[user objectForKey:@"email"];
g_user.gender=[user objectForKey:@"gender"];
[self fbLoggedIn];
} else {
[self fbLoginFailed:@"Login failed !!!"];
}
}];
} else if (state == FBSessionStateClosed || state == FBSessionStateClosedLoginFailed){
// If the session is closed
} else {
// handle errors
// Clear this token
[FBSession.activeSession closeAndClearTokenInformation];
[self fbLoginFailed:@"Login failed !!!"];
}
}