Facebook Graph API - 如何从公开资料中获取性别 [英] Facebook Graph API - How to get Gender from Public Profile
问题描述
我需要通过 Facebook Graph API 从 Facebook 用户的公开个人资料中检索他的性别.
I need to retrieve the gender from a Facebook user from his public profile via Facebook Graph API.
不幸的是,它并不总是有效.请参阅以下示例:
Unfortunately it is not always working. See these examples:
工作:https://graph.facebook.com/1423993568
{
"id": "1423993568",
"gender": "male",
...
}
不工作:https://graph.facebook.com/10152133878666403
{
"error": {
"message": "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100
}
}
但是当我直接通过网络打开用户ID时,它起作用了,我什至可以看到性别.(转到关于/联系方式和基本信息")我使用我的个人帐户登录,而不是该用户的朋友!http://www.facebook.com/10152133878666403
But when I open the user id directly via web, it works, and I can even see the gender. (Go to "About/Contact and Basic Info") I am logged in with my personal account and not a friend of this user! http://www.facebook.com/10152133878666403
有什么问题?是请求有问题还是 Facebook 的安全功能有问题?
What is the problem? Is it a problem with the request or a security feature from Facebook?
更新:
我可以做这样的解决方法,但前提是我使用浏览器登录:
I can do a workaround like this, but only if I am logged in with my browser:
打开此请求时,获取 app_scoped_user_id 并从重定向 URL 获取 Facebook 用户名:
Take the app_scoped_user_id and get the Facebook username from the redirect URL, when opening this request:
http://www.facebook.com/app_scoped_user_id/10152133878666403
--> https://www.facebook.com/shiffoni
--> https://graph.facebook.com/shiffoni
返回:
{
"id": "669926402",
"first_name": "Shiffoni",
"gender": "female",
"last_name": "Leonhardt",
"locale": "de_DE",
"name": "Shiffoni Leonhardt",
"username": "shiffoni"
}
还有其他获取性别、真实用户 ID 或昵称的想法吗?
Any other ideas to get the gender, real userId, or nickname?
推荐答案
正如 Facebook 员工在评论中已经回答的那样,这是不可能的,因为它不支持获取性别"或真正的 Facebook 用户身份证.
As already answered in the comments by a Facebook employee, it is simply not possible, because it is not supported to get the 'gender' or the real Facebook user id.
可能的解决方法:
- 使用性别 api(例如 genderize.io)根据第一个检索性别名称.
- 从 Facebook 上抓取性别信息(需要通过网络登录)来自用户的关于"页面.
- use gender api (e.g. genderize.io) to retrieve gender based on first name.
- scrape the gender information from the Facebook (need to be logged in via web) from the user about page.
这篇关于Facebook Graph API - 如何从公开资料中获取性别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!