我正在研究一個需要Facebook Login.I的ios應用程序,它已成功實現登錄過程。但現在我無法找到如何以及在哪裏可以獲得用戶個人資料信息,如名字,姓氏,個人資料圖片等...我的應用程序有權訪問名字,姓氏,個人資料圖片和電子郵件。獲取facebook在ios應用程序中的公開個人資料
回答
下面是獲得人public_profile使用的代碼最新的Facebook SDK v4.0.1。您需要使用FBSDKProfile來獲取個人資料。
-(void)viewDidLoad{
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
[self.view addSubview:loginButton];
self.loginButton.readPermissions = @[@"public_profile", @"email", @"user_friends"];
self.loginButton.delegate = self;
[FBSDKProfile enableUpdatesOnAccessTokenChange:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(profileUpdated:) name:FBSDKProfileDidChangeNotification object:nil];
}
-(void)profileUpdated:(NSNotification *) notification{
NSLog(@"User name: %@",[FBSDKProfile currentProfile].name);
NSLog(@"User ID: %@",[FBSDKProfile currentProfile].userID);
}
- (void) loginButton:(FBSDKLoginButton *)loginButton
didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result
error:(NSError *)error{
}
- (void)loginButtonDidLogOut:(FBSDKLoginButton *)loginButton{
}
此功能沒有得到所謂的在所有 - (空)loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)結果 錯誤:(NSError *)錯誤 – 2015-04-06 10:40:17
請確保您在@interface .h文件中包含
是的,我已經包含它,但函數沒有被調用。 – 2015-04-06 11:11:54
使用的通知方法,所以當它從Facebook它CA調用Facebook的委託方法
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleFBSessionStateChangeWithNotification:)
name:@"SessionStateChangeNotification"
object:nil];
後接收信息實施該方法
-(void)handleFBSessionStateChangeWithNotification:(NSNotification *)notification{
NSDictionary *userInfo = [notification userInfo];
FBSessionState sessionState = [[userInfo objectForKey:@"state"] integerValue];
NSError *error = [userInfo objectForKey:@"error"];
// Usually, the only interesting states are the opened session, the closed session and the failed login.
if (!error) {
// In case that there's not any error, then check if the session opened or closed.
if (sessionState == FBSessionStateOpen) {
[FBRequestConnection startWithGraphPath:@"me"
parameters:@{@"fields": @"first_name, last_name, picture.type(normal), email"}
HTTPMethod:@"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Set the use full name.
NSLog(@"first name and last name is %@",[NSString stringWithFormat:@"%@ %@",
[result objectForKey:@"first_name"],
[result objectForKey:@"last_name"]
]);
NSString *firstName = [NSString stringWithFormat:@"%@",[result objectForKey:@"first_name"]];
NSString *middleName = [NSString stringWithFormat:@"%@",[result objectForKey:@"middle_name"]];
NSString *lastName = [NSString stringWithFormat:@"%@",[result objectForKey:@"last_name"]];
NSString *email = [NSString stringWithFormat:@"%@",[result objectForKey:@"email"]];
// Set the e-mail address.
NSLog(@"email is %@", [result objectForKey:@"email"]);
}
else{
NSLog(@"%@", [error localizedDescription]);
}
}];
// [self.btnToggleLoginState setTitle:@"Logout" forState:UIControlStateNormal];
}
else if (sessionState == FBSessionStateClosed || sessionState == FBSessionStateClosedLoginFailed){
// A session was closed or the login was failed. Update the UI accordingly.
// [self.btnToggleLoginState setTitle:@"Login" forState:UIControlStateNormal];
// self.lblStatus.text = @"You are not logged in.";
}
}
}
- 1. 獲取任何Facebook用戶的公開個人資料
- 2. 獲取任何Facebook用戶的公開個人資料內容
- 3. Facebook PHP sdk錯誤。無法獲取公開個人資料
- 4. 如何在我的Android應用程序中獲取Facebook個人資料圖片?
- 5. 獲取Facebook用戶個人資料的所有公開相冊 - iOS Facebook的軟件開發工具包
- 6. IOS Facebook的單身人士,並獲取個人資料圖片
- 7. 如何在UIWebView中訪問公開的Facebook個人資料
- 8. 將個人資料信息保存在Facebook應用程序中
- 9. 從應用程序範圍的用戶ID獲取Facebook個人資料網址
- 10. 顯示Facebook的個人資料在我的應用程序
- 11. 獲取Facebook個人資料照片
- 12. 獲取Facebook頁面/個人資料URL
- 13. Android:從用戶名中打開Facebook應用程序中的個人資料
- 14. 從Facebook獲取用戶名和個人資料圖片iOS 7
- 15. iPhone應用程序檢索Facebook個人資料中的照片
- 16. 從公開個人資料中獲取Fousquare簽到數據
- 17. Facebook的API爲iOS,獲取朋友的個人資料圖片
- 18. 爲沒有個人資料的公司創建Facebook應用程序
- 19. 獲取Facebook的個人資料圖片使用Facebook用戶名
- 20. 如何從Android應用程序獲取Facebook個人資料照片?
- 21. 同時獲取更大的Facebook個人資料圖片和個人資料
- 22. iOS Facebook SDK獲取個人資料封面圖片
- 23. ios,facebook和獲取個人資料圖片
- 24. 應用程序訪問您的Facebook個人資料圖片
- 25. facebook應用程序需要個人資料圖片的尺寸
- 26. 獲取Facebook公共資料圖片
- 27. 如何在Facebook中獲取用戶個人資料?
- 28. 谷歌公開個人資料圖片
- 29. 在tableView中獲取Facebook個人資料圖片Cell的ImageView
- 30. 在Android中獲取Facebook的個人資料
https://developers.facebook.com/docs/ios/graph – 2016-10-04 10:45:10