把这段代码
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
// Process error
NSLog(@"error is :%@",error);
}
else if (result.isCancelled)
{
// Handle cancellations
NSLog(@"error is :%@",error);
}
else
{
if ([result.grantedPermissions containsObject:@"email"])
{
[self fetchUserInfo];
}
}
}];
您可以通过以下方式获取 facebook 用户信息
-(void)fetchUserInfo
{
if ([FBSDKAccessToken currentAccessToken])
{
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id,name,link,first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown , friendlists"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error)
{
NSString *photostring=[[[result valueForKey:@"picture"] objectForKey:@"data"] valueForKey:@"url"];
photostring = [photostring stringByReplacingOccurrencesOfString:@"&" withString:@"%26"];
NSLog(@"all data here is:%@",result);
NSLog(@"username is :%@",[result valueForKey:@"name"]);
NSLog(@"PhotoUrl is :%@",photostring);
NSLog(@"mail id is :%@",[result valueForKey:@"email"]);
}
}];
}
}
祝你的项目好运