Use Facebook API to retrieve count of unread group messages for a group - facebook

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

Related

How do I know if a Facebook Status/Photo/Link is Private?

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

Get List of Members of a public group from Facebook

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

FaceBook API for friends count

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

Facebook Graph API. How to get likes for comment?

I need to get ids of people who liked some comment.
For example, I have the post with id 246595548763188_464132103676197 , and this post has comment with id 464146663674741.
Then, I use Graph Api Explorer (https://developers.facebook.com/tools/explorer/)
Permissions: user_groups
Graph API URL: https://graph.facebook.com/464146663674741
Result:
{
"id": "464146663674741",
"from": {
"name": "Rostyslav Paranko",
"id": "100001288191932"
},
"message": "Українську мову доконають пуристи.",
"can_remove": false,
"created_time": "2013-06-03T19:10:57+0000",
"like_count": 8,
"user_likes": false
}
As you can see, like_count has value 8, but I can't see people who liked this comment (with ids and names). https://graph.facebook.com/464146663674741/likes returns empty array.
So, is it possible to get comment's likes using Graph API (or, maybe, FQL Query)?
Get the comment ID and make this Graph API request:
https://graph.facebook.com/COMMENT_ID?fields=likes
The comment ID is in fact the concatenation of:
the POST_ID (246595548763188_464132103676197),
the COMMENT_ID (464146663674741),
which would give in your case: 246595548763188_464132103676197_464146663674741.
So, this should work:
graph.facebook.com/246595548763188_464132103676197_464146663674741?fields=likes

FQL query of photos for Facebook users with large numbers of photos

I need to get photos of an FB user sorted by likes.
I ran this FQL query via Facebook JavaScript SDK to get them:
SELECT object_id, src_big, src_big_width, src_big_height, link, like_info, caption, created
FROM photo
WHERE owner = MANY_PICS_USER_ID ORDER BY like_info DESC LIMIT 10
The query fails for users with more than 3000 photos. Turns out there are a lot of those users. Related Facebook bug is here http://developers.facebook.com/bugs/438568326189781
As a note: removing "ORDER BY like_info" makes query work, but there is no easy way for me to get those pictures, sorted by likes
To reproduce:
Pick a FB friend with at least 3000 photos, get their user Id, and run the above query (replacing MANY_PICS_USER_ID) in API GRAPH EXPLORER.
What is the best workaround? Or, can you suggest the easiest light-weight Open Graph solution?
To sort photos by likes you need the following:
Run the query which gives first 100 results (replace me with user id):
http://graph.facebook.com/me/photos?fields=id,source,likes&limit=100
Which return the following data structure:
"data": [
{
"id": "1234567890",
"source": "http://photo.url.in.facebook.cdn.com/",
"created_time": "2012-09-13T22:52:34+0000",
"likes": {
"data": [
{
"id": "1234567890",
"name": "Full Name"
},
.....
"paging": {
"next": "https://graph.facebook.com/1234567890/likes?limit=25&offset=25"
}
}
},
{
"id": "312323232323",
"source": "PICTURE_URL",
"created_time": "2012-09-12T20:54:27+0000",
"likes": {
"data": [..]
}
},
....
"paging": {
"previous": "http://PREVIOUS_URL?fields=id,source,name,height,width,link,likes&limit=100&since=123456",
"next": "http://NEXT_URL?fields=id,source,name,height,width,link,likes&limit=100&until=234567"
}
If total number of pictures is more than 100, run all next queries,
from the "next" link until the num of pics will be less then 100.
For every picture you need to count total number of likes. If the
number of likes is more than 25, run extra query from
likes.paging.next until number of likes will be < 25 and get the
total quantity.
Sort all those pics by number of likes.
So for the user with 3000 pics it will be in total 30 calls + extra calls for each picture with more than 25 likes.