Facebook Graph API: user gender - facebook

The old Facebook API provided the user sex/gender as part of the default user data. Apparently the new Graph API does not provide that information, even though the documentation says that it does.
I've heard people say that you need to request special permissions to get it and other pieces of data, but I have not been successful in getting it to work.
Does anyone have an example, using the Facebook Graph API, of how to get the user's gender and/or location (city/state/country/whatever)?

You need user_location permission to get the location according to the API reference.
GET https://graph.facebook.com/USER_ID?fields=gender,location
The Graph API tool explorer is a really handy tool for checking the output.

Just FYI, location (City and state only, country is still missing) and gender have been added to the Graph API sometimes today.
I was testing an app tonight and noticed there was a couple more fields :)

I see this has an open bounty even though the question is really really old.
You can get the gender of any user using Open Graph even without any access_token.
GET https://graph.facebook.com/userid
json_decode the data
gender will be in the `gender` element of the returned array.
EDIT : user location, hometown, country etc are no more there in the /me. seems like Fb removed those, even if they are public.
Hope this helps

As far as I can tell some permissions like user_location simply aren't working at the moment. I can get email permissions and some others but for most of the user_... ones, nope. Yes they are wrong about gender as part of default data and there appears to be no permission for it either. So use the old api until the kinks in the new one get worked out.

Related

Facebook Graph API is not returning (From) field for a comment?

I have a question that recently I am seeing that Facebook graph API is not returning (from) field for a comment.
Ex:- https://graph.facebook.com/v2.6/{post_id}/comments?fields=from%2Ccan_like&access_token={access_token} OR,
If you are debugging through graph API explorer then:
{post_id}/comments?fields=from,can_like
I do not find any documentation on any change from the Facebook side. Please do let me know if I am doing something wrong.
Thanks in advance.
https://developers.facebook.com/docs/graph-api/changelog/version2.11#gapi-90
/page/* — User information will not be included in GET responses for any objects owned by (on) a Page unless the request is made with a Page access token. This affects all nodes and edges that return data for objects owned by a Page.
I have had this same problem. This happened to me because "my app was in Development mode", even with having all the correct permissions, the from field is not returned, this is a behaviour I tested few times.
When I switched my app to Live mode, even though it is not yet approved, the Graph API started to return the from field for posts and comments on posts.
If your scenario is similar to mine, then you need to switch your Facebook App into Live mode.

Get list of events user is attending on Facebook

I'm trying to get list of events my friend / user attends. This info is publicly visible through Facebook pages.
I'm making a request to /userid/events but it returns empty array of results, though user does have upcoming events and calling /me/events is working. (all is ran in graph explorer)
I couldn't find any documentation about any limitations or required permissions to explain why it's not working e.g. this link
Is it a bug? How to workaround it?
You can use /userid/events with a user who auzhorized your App, but using /me/events is recommended. Either way, just because stuff is public on facebook.com does not mean you can get it with the API. You always need to authorize users before you can get any data, for privacy reasons.
In other words: It´s not a bug, there is no workaround, it´s not possible without user authorization.

Get Facebook user work

I'm trying to write some application that scan user's group posts. When I read the group feed posts using the API I’m interested to get some information on the one who posted this post ('from' field). The graph API today gives only the id and the name of this person. I'm interested also in his work place. I tried taking the user id and to access the / resource and to get his work field , but this field is not returned. When I’m looking on the same user profile in Facebook I see his work place is public, even I’m not connected with him.
Anything I can do to get this user work with the existing Facebook API?
Normally, if the work history info is not public, you'll need the "user_work_history" permission (see https://developers.facebook.com/docs/facebook-login/permissions#reference-extended-profile).
If it's public, you can try calling the
/{USER_ID}?fields=id,work

Can't access friends's informations with the graph API

I'd like to retrieve, for instance, a friend's birthday, using the graph API.
So I pick a friend whose birthday my profile can see, go to the Graph API Explorer, generate an access token with the friends_birthday privilege, and input [friend_name]/?fields=birthday and... it doesn't return anything. The birthday field on the side is grayed out, with a mouse-over text that says
"Field is empty or disallowed by the access token".
The worst part is that it works fine for some friends, but not for others. Is it related to the level of visibility they set for this information on their profile? I assumed that the app can see everything my profile can see (if I give it full privileges), but maybe that's not the case. Or is there something wrong with my request?
I had the same problem and the answer is that your friend can change the permissions it gives to apps. So, for the Graph API Explorer app your friend would need to give the user_birthday permission to the app in order for you to see their birthday through the app (and you have to give the app the friends_birthday permission as well).
See here for the comment that helped me figure that out.

How would I get a list of 'friends' who have added my Facebook application?

I'm really struggling with something that should be a simple matter: Showing a user of my Facebook app a list of their friends also using the app. Is there nothing built into the APIs to allow such a common request?
The only thing I can think of to do is to get the list of the user's friends, and then get all the users from my database who are in that list, and then fetch information for each of those facebook ids. But that seems an extremely roundabout way of doing things...
The only way I've found to do this is to use FQL and a previously documented, but now undocumented field:
SELECT uid,name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=<user's uid>) AND is_app_user=1 ORDER BY name
The undocumented field is the user.is_app_user, which is listed in the old documentation wiki but not in the shiny new docs. No idea if this means it'll be removed in the future, but there doesn't seem to be any other way to get this data with the new Graph API.
Just in-case you're still using the old REST API, you can also call the friends.getAppUsers method.
You can actually use Facebook's old REST API to do this by sending a GET request to: https://api.facebook.com/method/friends.getAppUsers
If you need JSON data back, then add the parameter format=json
You need an access token to do this. See the documentation here:
http://developers.facebook.com/docs/reference/rest/friends.getAppUsers/