Reputation: 1674
how to find a facebook url is community url or profile url using facebook API
For example http://www.facebook.com/adelphi.panthers
http://www.facebook.com/BryantAthletics
Which is profile url and which is community url, how to find?
Upvotes: 0
Views: 400
Reputation: 1702
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());
Upvotes: 0
Reputation: 2596
Well as @Lix has suggested you could do something like this:
Request: https://graph.facebook.com/BryantAthletics?fields=gender
HTTP Response: 400 Bad Request
JSON Response:
{
"error": {
"message": "(#100) Unknown fields: gender.",
"type": "OAuthException",
"code": 100
}
}
This tells us its NOT a User object. But then it could be a group or a page.. So you need to make another request using an attribute that is unique either to a group or page. Depending on how you make the request, you could decide to handle the result accordingly.
Consider,
Request: https://graph.facebook.com/adelphi.panthers?fields=gender
HTTP Response: 200 OK
JSON Response:
{
"gender": "female",
"id": "1360823630"
}
Now this tells us that the gender attribute exist within this Facebook object and so it is definitely a user.
I'm assuming you are using JQuery to capture and parse the response. Then you would check for the error attribute in the JSON variable to determine the object type.
Upvotes: 2
Reputation: 47966
The links you provided were for a Facebook user and for a Facebook page. I'm going to assume that by "community url" you mean Facebook page...
Ok, so I think it will be pretty simple to detect what is a Facebook Page and what is a User according to the username (or ID).
All you would have to do (in these cases), is query the Graph API with the username -
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"
}
As you can see, this call to the API returned a gender parameter. Pages can not have genders so we can assume this is a Facebook User.
https://graph.facebook.com/BryantAthletics
{
"name": "Bryant Athletics",
"is_published": true,
"website": "bryantbulldogs.com",
"username": "BryantAthletics",
...
"category": "School sports team",
...
}
You can see here that much much more information is being returned to us. I think the Category parameter is a good indication that this specific username is related to a page. Users can not choose a category for themselves...
Upvotes: 2