我如何从 facebook public 个人资料中获取性别 Facebook IOS Swift SDK
how do i get gender from facebook public profile Facebook IOS Swift SDK
我之所以需要获取 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]
我没有得到用户的性别。如何获取用户的性别?
此致
您可以使用 Graph api 获取这些详细信息。检查这个 link 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
})
我之所以需要获取 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]
我没有得到用户的性别。如何获取用户的性别?
此致
您可以使用 Graph api 获取这些详细信息。检查这个 link 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
})