我之所以需要获得Facebook用户的性别,是因为我的应用只适合女性,并且通过获得用户的性别可以解决很多应用问题。
代码
loginManager.logIn(readPermissions: [ .publicProfile, .email ], viewController: self) { loginResult in
switch loginResult {
case .failed(let error):
print(error)
case .cancelled:
print("User cancelled login.")
case .success(_, _, let accessToken):
if let userId = accessToken.userId {
}
}
}
我从facebook服务器获得的结果
["picture": {
data = {
height = 200;
"is_silhouette" = 1;
url = "https://www.picture.com";
width = 200;
};
}, "last_name": Test, "email": test123@gmail.com, "id": 1234556, "first_name": Airsoft]
我没有得到用户的性别。如何获得用户的性别?
此致
答案 0 :(得分:2)
您可以使用Graph api获取这些详细信息。请检查此链接https://developers.facebook.com/docs/graph-api/reference/user
let request = FBSDKGraphRequest(graphPath: "\(user-id)", parameters: ["fields" : "id,name,email,birthday,gender,hometown" ], httpMethod: "GET")
request?.start(completionHandler: { (connection, result, error) in
// Handle the result
})