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

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.

Related

How to get Facebook page links + like count for each?

How do I get the links posted in a Facebook page AND the # of likes that link got without making extra calls?
Right now I am making this call, and it gives me all the posts that are links, posted in a Facebook page. How do I get the like count for each post? I simply want to know how many people liked that post.
https://graph.facebook.com/#{facebookId}/links?access_token=TOKEN&limit=20
To get the likes count for each post that is a link, the following query:
https://graph.facebook.com/#{facebookId}/links?fields=likes.limit(1).summary(true)&access_token=TOKEN&limit=20
gives you a response like this:
{
"data": [
{
"id":
"created_time:"
"likes": {
...
"summary": {
"total_count": 23
}
}
},
{
...
}
]
}
The total_count value is what you want.

Getting images from facebook group album

I'm having a problem with the Graph API / FQL and I have searched however no solution has come up.
I'm unable to retrieve photos from a group album.
I can retrieve a lot of information regarding that group album which indicates that a group album is just a regular album:
SELECT description, owner, photo_count, type, like_info,
cover_pid, comment_info FROM album WHERE object_id = '1382173765340875'
{
"data": [
{
"description": "10 Desafio Outros!!!",
"owner": 1455136613,
"photo_count": 8,
"type": "normal",
"like_info": {
"can_like": true,
"like_count": 1,
"user_likes": true
},
"cover_pid": "6249764165120950711",
"comment_info": {
"can_comment": true,
"comment_count": 0,
"comment_order": "chronological"
}
}
]
}
Calling "/1382086785349573" gives me the group information.
Calling "/1382086785349573/albums" gives me a list of all the albums in the group including ID, album name and even correct count.
but "albumid/photos" where album ID was retrieved from previous call returns an empty array
Also "/groupid/photos" returns an empty data[] array.
Can anyone tell me why this happens? I already removed my app from sandbox mode but still showing the same problem.
I don't understand why it can retrieve album information including items count and etc but not the photos in it.
Thanks in advance for any help.

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

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

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

facebook graph can not get comments

After Search post from graph
https://graph.facebook.com/search?q=watermelon&type=post&fields=from,message,picture,link,name,caption,comments,description,created_time,id&token=XXXXXXXXXXXXX
here will return some data. In the third post:
"from": {
"name": "Alessio Mrbillyplus Frustaci",
"id": "1665626783"
},
"picture": "http://external.ak.fbcdn.net/safe_image.php?d=AQDGoBK_lUeeMb5x&w=130&h=130&url=http\u00253A\u00252F\u00252Fi3.ytimg.com\u00252Fvi\u00252Fjo5GcYeh7XA\u00252Fdefault.jpg",
"link": "http://www.youtube.com/watch?v=jo5GcYeh7XA&feature=share",
"name": "Herbie Hancock \"Watermelon Man\"",
"caption": "www.youtube.com",
"description": "From the 1973 album \"Headhunters\" here's Herbie Hancock with \"Watermelon Man\" Sampled by Super Cat \" Dolly My Baby\" LL Cool J \"1-900-LL Cool J\" Shaquille O'N...",
"created_time": "2011-09-17T17:44:48+0000",
"id": "1665626783_235117223205324",
"comments": {
"data": [
{
"id": "1665626783_235117223205324_3043725",
"from": {
"name": "Alessio Mrbillyplus Frustaci",
"id": "1665626783"
},
"message": "La enne e la doppia effe aaaaaa",
"created_time": "2011-09-17T17:45:52+0000"
}
]
}
},
It is clearly that it has comments in it. So the PostID is 1665626783_235117223205324 and CommentID is 1665626783_235117223205324_3043725? But when I tried search a post or comments, the data return empty.
https://graph.facebook.com/1665626783_235117223205324?access_token=XXXXXXXXXXX//empty
https://graph.facebook.com/1665626783_235117223205324/comments?access_token=XXXXXXXXXXX//empty
https://api.facebook.com/method/fql.query?
callback=json&
query=SELECT%20comments%20FROM%20stream%20WHERE%20post_id%20%3D%20'1665626783_235117223205324'&access_token=XXXXXXXXXXXXXX //empty
What is the big problem?
There may be privacy settings in place which prevent the current user from seeing the posts or comments, where are those comments posted? Are you accessing them with an access_token from a user who can see the content?
As Mahima said, both of those calls should be working and i've tested equivalent calls with posts from my own news feed or page walls.
A call to /1665626783_235117223205324 for me returns false, which indicates i don't have permission to view the item.
This could also be a bug, but you'd need to have a very clear set of sample data to demonstrate the issue so it can be reproduced by Facebook
I tried with post id and comment id both as
http://graph.facebook.com/COMMENT_OR_POST_ID?access_token=APPLICATION_ACCESS_TOKEN
both are working ..
Make sure the access_token you are using is either of the application which you used for posting on a user's wal.. Or the access_token has sufficient read_stream and offline_access permission of the user ..