如何从Facebook API获取完整的userDetails
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment to automatically sign in the user.
_signInFacebook.delegate = self;
_signInFacebook.readPermissions = @[@"email",@"birthday"];
}
- (void) loginButton:(FBSDKLoginButton *)loginButton
didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result
error:(NSError *)error{
NSLog(@"LOGGED IN TO FACEBOOK");
[self fetchUserInfo];
}
-(void)fetchUserInfo {
FBSDKAccessToken* token = [FBSDKAccessToken currentAccessToken];
[[[FBSDKGraphRequest alloc] initWithGraphPath:[NSString stringWithFormat:@"/%@",token.userID] parameters:@{ @"fields":@"id,name,first_name,middle_name,last_name,email,gender,location,picture.type(large),age_range,verified,birthday"} HTTPMethod:@"GET"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@", result);
if ([result isKindOfClass:[NSDictionary class]])
{
NSLog(@"%@",result);
[USERDEFAULTS setObject:result forKey:PROFILE_KEY];
}
}
else
{
NSLog(@"Error fetchUserInfo %@",error);
}
}];
}
期望从Facebook API获取手机号码
答案 0 :(得分:1)
您应该使用“图片”代替“照片”来获取用户个人资料照片。 您可以从accessToken获取userID,如:
FBSDKAccessToken* token = [FBSDKAccessToken currentAccessToken];
NSString *ID = token.userID
登录时:
要获得生日,您需要获得“user_birthday”的许可
要获取位置,您需要权限“user_location”
在您的应用中实施之前,您可以在Facebook Graph API Explorer中测试所有内容。
要在登录时请求权限,请提供示例代码:
FBSDKLoginManager* login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"public_profile",@"email",@"user_birthday"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
//your code to handle login result
}];