I want to get list of ALL members of a public group using Facebook API ( preferably via FQL ). I checked https://developers.facebook.com/docs/reference/fql/ .. The table group_member does not provide such API !
Any inputs ? As this is a public group ; do we need to send any auth_access tokens ! Something like https://graph.facebook.com/fql?q=SELECT%20url,normalized_url,share_count,like_count,comment_count,total_count,commentsbox_count,comments_fbid,click_count%20FROM%20link_stat%20WHERE%20url='google.com'
works fine without any tokens..
No permissions are needed.
To read the group_member table you need:
any valid access_token if the group is public (i.e. the group's
privacy setting is OPEN)
Source: https://developers.facebook.com/docs/reference/fql/group_member/
Using Graph API
GROUP_ID/?fields=members
{
"id": "GROUP_ID",
"members": {
"data": [
{
"name": "User's name",
"administrator": false,
"id": "User's ID"
},
...
Using FQL
SELECT uid FROM group_member WHERE gid = GROUP_ID
{
"data": [
{
"uid": "100004123456789"
},
...
just follow this link https://www.facebook.com/groups/{your group id}/apps/store and add your facebook app
Related
Since Facebook API update to v2.11, I cannot get User Id and Name from comments on FanPage Wall Post. Anyone can help/explain?
Usually I used this :
https://graph.facebook.com/[POST_ID_PAGE]/comments?order=reverse_chronological&access_token=[YOUR_ACCESS_TOKEN]
And the result just like :
{
"data": [
{
"created_time": values_date_TMZ,
"from": {
"name": USER_NAME,
"id": USER_ID
},
"message": THE_COMMENT,
"id": THE_COMMENT_ID
}
}
You need a Page Token now, to get user names - check out the changelog:
https://developers.facebook.com/docs/graph-api/changelog/version2.11#gapi
I assume you are using an App Token at the moment.
Edit: Of course it has to be a Page Token of the Page with the comment. And of course you need to manage the Page - else you would not even get a Page Token.
When I'm getting a status/link/photo from facebook API, how do I know if it has been shared with the public or if it's a private post?
Also - is there a way to query only public posts?
I'm currently using the /<username>/status /<username>/links /<username>/photos endpoints.
With the graph api
From the 3 endpoints you are using, only one gives you access to the privacy settings the /<username>/links. It returns a privacy object, something like this:
{
"id": "USER_FB_ID",
"links": {
"data": [
{
"id": "ID_OF_THE_POST",
"from": {
"name": "Fábio Antunes",
"id": "USER_FB_ID"
},
"message": "Check this awesome link",
"privacy": {
"description": "Friends; Except: Restricted",
"value": "ALL_FRIENDS",
"allow": "",
"deny": "",
"networks": "",
"friends": ""
},
(etc....)
With FQL
To solve your problem you could use FQL this way you can get the 3 endpoints that have public access.
For the links you can use this query:
Select link_id,owner_comment, title, url, privacy FROM link WHERE owner = me() AND privacy.value='EVERYONE'
note: check the link table to see if there are any fields that you may want to add to this query
Since the links table from the 3 endpoints is the only with privacy settings structure to get the user photos and statuses that are public you will have to use the privacy table.
To get all the users public photos I made 2 joins, first I'm getting the user photos, then I want the privacy settings of the photos that are available to everyone and then I select the photos that have the privacy settings public:
SELECT caption,src_big FROM photo WHERE object_id IN (SELECT id FROM privacy WHERE value='EVERYONE' AND object_id IN (SELECT object_id FROM photo WHERE owner=me()))
note: check the photo table to see if there are any fields that you may want to add to this query
To get the public statuses it's the same process for the photos, two joins:
SELECT status_id , message, place_id FROM status WHERE status_id IN (SELECT id FROM privacy WHERE value='EVERYONE' AND object_id IN (SELECT status_id FROM status WHERE uid=me()))
note: check the status table to see if there are any fields that you may want to add to this query
Does there exist any way to get group by it's alias (username)?
SELECT id, name, pic_big, type, url, username FROM profile WHERE username='somealias'
works for pages, but doesn't works for groups! For groups it returns
(#803) Some of the aliases you requested do not exist: somealias
profile table is like a parent class for user, group, page, event, or application tables. (see https://developers.facebook.com/docs/reference/fql/profile/)
It has field username but values in this field are filled from related tables, and table group has no field username (see https://developers.facebook.com/docs/reference/fql/group). So when we query profile using where id = someid we get such results:
SELECT id, name, pic_big, type, url, username FROM profile WHERE id= '195466193802264'
{
"data": [
{
"id": 195466193802264,
"name": "Facebook Developers",
"pic_big": "https://www.facebook.com/images/litestand/bookmarks/sidebar/icons/groups/icon-default.png",
"type": "group",
"url": "https://www.facebook.com/groups/195466193802264/",
"username": ""
}
]
}
As you can see, username is empty for group.
update
After some investigation I found that groups CAN have usernames. Oficially they can't, but group's email part before # symbol is it's username.
When you query the profile if you only specify its username you receive nothing. But if you'll add its name your group will appear.
Example:
SELECT id, name, pic_big, type, url, username FROM profile
WHERE username = 'rock.mfc' and type = 'group'
will result
{
"data": [
]
}
But the query
SELECT id, name, pic_big, type, url, username FROM profile
WHERE name = 'ROCK MUSIC FANS CLUB' and username = 'rock.mfc' and type = 'group'
will give the required result:
{
"data": [
{
"id": 268045023346892,
"name": "ROCK MUSIC FANS CLUB",
"pic_big": "https://www.facebook.com/images/litestand/bookmarks/sidebar/icons/groups/icon-guitar.png",
"type": "group",
"url": "https://www.facebook.com/groups/rock.mfc/",
"username": "rock.mfc"
}
]
}
Hope it'll help you.
There is the question about fetching count of user friends via FaceBook API.
I want to get the number of friends only have USER_ID of the any facebook user. As I know I can get it using FQL like:
SELECT friend_count FROM user WHERE uid = X
But for some users this value is null or there is no value. Please advice is there another way to get this value?
That user might be keeping that information private. In that case, you cannot fetch that information.
You just check the following link. You need to generate token (by clicking on Get Token you will get it) with data you want from facebook API, need to select friends option to get the friend count.
https://developers.facebook.com/tools/explorer/?method=GET&path=me%3Ffields%3Did%2Cname%2Cfriends&version=v2.8
FB.api(
'/me',
'GET',
{"fields":"id,name,friends,link,email,gender,picture,first_name,last_name,cover"},
function(response) {
// Insert your code here
}
);
after executing this you will get this in response as
{
"id": "XXXXXXXXXX",
"name": "Test test",
"friends": {
"data": [
],
"summary": {
"total_count": 14
}
}
}
total_count will be your friend count
I'm trying to find a way to get a count of unread posts for groups, like the ones shown on the left hand-side menu of Facebook.com
I was able to find the reference to Group table in FQL, but I can't see any field there representing the count of unread messages
Am I in the right place to find this data or is there some other way to retrieve it?
This is available as the unread field of the Group in FQL or Graph API, but in FQL this is the group_member table, not the group table.
To access the unread count of a group you'll need the user_groups Permission from the user.
Sample Graph API call:
/me/groups?fields=unread
Response:
{
"data": [
{
"name": "Facebook Developers",
"version": 1,
"id": "146797922030397",
"unread": 11,
"bookmark_order": 1
},
// snip
Sample FQL Query:
select gid, unread from group_member where uid = me()
Sample response:
{
"data": [
{
"gid": "146797922030397",
"unread": 3
}
// removed other groups