您好我只是使用此api获取用户详细信息但我无法获得用户名请帮助我
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:[NSDictionary dictionaryWithObject:@"id,first_name,last_name,gender,email,picture.type(large),groups" forKey:@"fields"]]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (error==nil) {
}else {
NSLog(@"facebook erro : %@ ",error);
}
}];
答案 0 :(得分:0)
您需要请求权限才能访问非公开的数据。
Check the blog here, it mentions how to request permission for private data.
这是上述博客的片段
let loginManager = FBSDKLoginManager()
let permissions = ["public_profile", "email","username"] //not sure username is to be used or user_name.
let handler = loginManager.logInWithReadPermissions(permissions, fromViewController: self, handler: handler)
用户授予访问其私人数据的权限。您将能够检索数据。
答案 1 :(得分:0)
Facebook iOS sdk在swift 3中获取用户名和电子邮件 -
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, email"]).start(completionHandler: { (connection, result, error) -> Void in
if (error == nil){
let fbDetails = result as! NSDictionary
print(fbDetails)
}else{
print(error?.localizedDescription ?? "Not found")
}
})