如何使用facebook API查找facebook url是社区url或配置文件url
例如http://www.facebook.com/adelphi.panthers
http://www.facebook.com/BryantAthletics
哪个是个人资料url,哪个是社区url,如何查找?
发布于 2012-10-16 15:46:59
正如@Lix所建议的,你可以这样做:
请求: https://graph.facebook.com/BryantAthletics?fields=gender
HTTP响应: 400错误请求
JSON响应:
{
"error": {
"message": "(#100) Unknown fields: gender.",
"type": "OAuthException",
"code": 100
}
}
这告诉我们它不是一个用户对象。但是,它可以是一个组或一个页面。因此,您需要使用对组或页面唯一的属性发出另一个请求。根据您发出请求的方式,您可以决定相应地处理结果。
考虑一下,
请求: https://graph.facebook.com/adelphi.panthers?fields=gender
超文本传输协议响应: 200 OK
JSON响应:
{
"gender": "female",
"id": "1360823630"
}
现在,这告诉我们,性别属性存在于这个Facebook对象中,因此它肯定是一个用户。
我假设您正在使用JQuery来捕获和解析响应。然后检查JSON变量中的error属性以确定对象类型。
发布于 2012-10-16 15:27:24
您提供的链接是为Facebook用户和Facebook页面提供的。我假设“社区网址”指的是Facebook页面……
好的,所以我认为根据用户名(或ID)来检测什么是Facebook页面和什么是用户是非常简单的。
您所要做的就是(在这些情况下)使用用户名查询Graph API -
https://graph.facebook.com/adelphi.panthers
{
"id": "1360823630",
"name": "Adelphi Panthers",
"first_name": "Adelphi",
"last_name": "Panthers",
"link": "https://www.facebook.com/adelphi.panthers",
"username": "adelphi.panthers",
"gender": "female",
"locale": "en_US",
"updated_time": "2012-10-09T12:51:38+0000"
}
如您所见,此API调用返回了一个性别参数。页面不能有性别,所以我们可以假设这是一个Facebook用户。
https://graph.facebook.com/BryantAthletics
{
"name": "Bryant Athletics",
"is_published": true,
"website": "bryantbulldogs.com",
"username": "BryantAthletics",
...
"category": "School sports team",
...
}
你可以在这里看到更多的信息被返回给我们。我认为Category参数是一个很好的指示,表明这个特定的用户名与页面相关。用户无法为自己选择类别...
发布于 2013-11-27 18:46:02
If you are working with java then don't pass any parameter of gender type.
it will automatically accept.
I had the same problem but now its resolved.
My working code is:
User user = client.fetchObject("username", User.class);
System.out.println("Gender: " + user.getGender());
https://stackoverflow.com/questions/12909437
复制相似问题