代码:
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions: @[@"public_profile"]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@"Process error");
} else if (result.isCancelled) {
NSLog(@"Cancelled");
} else {
NSLog(@"result:%@", result);
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@", result);
}
}];
}
NSLog(@"Logged in");
}
}];
我使用Facebook sdk4进行登录集成。它工作正常,身份验证也获得成功。如何获取名字,姓氏,个人资料网址,生日等信息.FBSDKGrpahRequest处理程序单独返回id和name.How我能得到其他细节吗?
答案 0 :(得分:3)
您需要在调用要检索的特定数据时设置参数值。例如:
parameters:@{@"fields": @"id, name"}
这也是:
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name"}];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {}];
在上面的代码中,您将参数设置为" nil",因此要使代码按照您的意愿运行,请执行以下操作:
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions: @[@"public_profile"]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@"Process error");
} else if (result.isCancelled) {
NSLog(@"Cancelled");
} else {
NSLog(@"result:%@", result);
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@", result);
}
}];
}
NSLog(@"Logged in");
}
}];
出于您的目的,您想要请求如下参数:
parameters:@{@"fields": @"id, name, first_name, last_name, birthday, picture"}