我有兩個與iOS和Facebook API相關的問題。在iOS本地存儲Facebook用戶數據
1)如何在用戶點擊登錄btn獲取用戶數據時自定義facebook登錄視圖。
2)在我的應用程序中,我想使用Facebook API。通過這種方式,我可以在下面的這個方法中檢索用戶數據。但是,我怎樣才能將這些用戶數據保存在我的應用程序本地。
非常感謝您的幫助!
[FBSession openActiveSessionWithReadPermissions:@[@"email",@"user_location",@"user_birthday",@"user_hometown"]
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
switch (state) {
case FBSessionStateOpen:
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error){
if (error) {
NSLog(@"error:%@",error);
}
else
{
// retrive user's details at here as shown below
NSLog(@"FB user first name:%@",user.first_name);
NSLog(@"FB user last name:%@",user.last_name);
NSLog(@"FB user birthday:%@",user.birthday);
NSLog(@"FB user location:%@",user.location);
NSLog(@"FB user username:%@",user.username);
NSLog(@"FB user gender:%@",[user objectForKey:@"gender"]);
NSLog(@"email id:%@",[user objectForKey:@"email"]);
NSLog(@"location:%@", [NSString stringWithFormat:@"Location: %@\n\n",
user.location[@"name"]]);
self.fbUserDataDict = [NSDictionary的dictionaryWithDictionary:用戶];
}
}];
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
} ];
不要忘記在保存數據時要求用戶同意。這將是非法的,否則http://webmasters.stackexchange.com/questions/24734/am--allowed-to-save-basic-user-data-from-facebook-in-my-own-web-apps-數據庫#comment23335_24746 – jbouaziz
嗨pacman321,我只提到「基本賬戶信息」就像:姓名,電子郵件,性別,生日,當前城市和個人資料圖片網址。 –