我尝试使用Facebook SDK从我登录的用户那里收到电子邮件。以下是我的两种登录方法
-(void)loginButtonClicked {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions: @[@"public_profile", @"email", @"user_friends"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@"Process error");
} else if (result.isCancelled) {
NSLog(@"Cancelled");
} else {
[self getFBUSerData];
NSLog(@"Logged in");
}
}];
}
- (void) getFBUSerData {
if (FBSDKAccessToken.currentAccessToken != nil) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@ and Email : %@", result,result[@"email"]);
}
}];
}
}
日志中的结果:
(lldb) po result
{
id = 42357***4506554;
name = "Fname Lname";
}
但没有电子邮件或朋友列表。任何帮助如何获得这些?
答案 0 :(得分:1)
您必须在getFBUserData()中分配所需的参数。
这样的事情:
- (void) getFBUSerData {
if (FBSDKAccessToken.currentAccessToken != nil) {
NSDictionary *dict = [[NSDictionary alloc] initWithObjects:@[@"id, name, first_name, last_name, picture.type(large), email"] forKeys:@[@"fields"]];
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:dict]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@ and Email : %@", result,result[@"email"]);
}
}]; }
}