Using the Facebook Graphi API, how can I retrieve paginated photos in which my friends are tagged from a specific album? - facebook

I want to show the photos of an album in my app. Using the graph API i am able to filter and page by month, like below, which is great. I loop trough the results and get the photo for each id. Best of all, the GRAPH API also gives me a 'next' and 'previous' paging link. Very useful.
http://graph.facebook.com/[photo-album-id]/photos/?fields=id&limit=6&since=last month
But now i want to retrieve only those ids filter in two ways:
Only retrieve those in which the user is tagged
Only retrieve those in which the user & his/her friends are tagged.
I couldn't find any way to do this, with the graph API. Is there an alternative via FQL, that still has the paging in there?
Last alternative I can think of is program is in FQL, and do the paging myself.
p.s. I am doing this in Javascript currently.

You can retrieve photos the current user is tagged in in a specific album with this FQL call:
select object_id, src, album_object_id from photo where pid in (select pid from photo_tag where subject=me()) and and album_object_id=somenumber
To retrieve photos in which the user's friends are tagged, for a specific album:
select object_id, src, album_object_id from photo where pid in (select pid from photo_tag where subject in (select uid2 FROM friend WHERE uid1 = me())) and album_object_id=somenumber
As far as I know these results will not be paginated. For a detailed take on how to paginate fb queries see the Facebook Developer Blog: How-To: Paging with the Graph API and FQL

After a little play with the Graph Explorer (https://developers.facebook.com/tools/explorer/) I come up with this solution. You can make a call to Graph API as follows
/me?fields=friends.limit(5).fields(photos.limit(5))
The first limit is for how many friends you want to get and the second limit is how many photos you want from each friend.
At the end of the data there already is the next page URL.
I only tested on the explorer but should work.
Hope that helps,
Doruk

Related

Get recent photos from the Facebook v2.1+ graph api

Facebook's FQL was deprecated after v2.0. The website I'm working on previously had a "Recent photos" feature that populated recent photos using this FQL:
var fql = 'SELECT object_id, aid, images, album_object_id, created, modified, position, caption
FROM photo
WHERE aid in (SELECT aid, owner FROM album WHERE owner = me())
ORDER BY created DESC
LIMIT 59';
I'm trying to figure out a comparable way to do that using the graph api. the /photos endpoint is probably what I want, but I can't figure out if it has a valid order queryparam.
In postman I've been messing around with this:
https://graph.facebook.com/v2.2/10151316456544622/photos?fields=picture,name,source,created_time&limit=20&order=-created_time&debug=all&access_token=CAAL7TZAyo4RUBAOJe4Jgjdt6NZAqcajRghEGdKwraq4X1yZAKjvgXj4xXAZCoyZCkzMO84mTMJ90Vp5CEfJsT1WsoOwif2QZCS00bGqZAVxqmZChMUqKQmNsu2DvZCoY42ZC5fSBAxUuNCqTWg1QZCBZCz5oQx3wcNZCZCPUHOXMu5i5jZCOTGIiPWrAeTlzhFBqkvoZBZAPSJRhlkdxyrKPmpmOqgKrUeD13TdOtKU4ZD
The access_token is of a FB test account, feel free to go nuts. I'm not getting any debug information. There doesn't appear to be anything in the docs about how to change the order of photos.
This example url might not be the best. There's only 7ish public photos for this account, but I will potentially be getting recent photos from accounts with 1000s of photos. I don't want to just get all photos and reverse the list. I want to the most recent 20 photos in one call.
Any ideas? Is there order documentation that I've missed?
There is no direct way to achieve this using the Graph API, but you can use Real Time Updates to get notified about changes to the photos of a user.

Getting user profile pictures without FQL - graph api v2.2

I was using FQL to get all the photos in the user profile pictures album.
Since facebook decided to deprecate FQL in their latest version of graph api, im looking for the easiest and fastest way to get the user profile pictures (all of them)
I was using this FQL:
SELECT object_id, src_big, src_big_height FROM photo WHERE aid in (SELECT aid FROM album WHERE owner = 'XXXX' AND type = 'profile') LIMIT 20"
Any graph method that would get me the equivalent in 1 graph call? (I know i call call for /user/albums and to use the album id later to get the photos, but i don't want to seperate it to 2 calls)
Thanks alot
Ok, the best I could came up was using graph api field expansion:
https://graph.facebook.com/me?fields=albums.limit(1).fields(name,photos.fields(name,picture,source,images))
Im assuming the first album is the profile pictures.
Hope this can help others :)

How to get Facebook images in which my friend is tagged

I am developing a web application using Java. I need to access my friends photos and need to select the photo in which he is tagged. ( i.e ) His face should be there in that photo.
How to do it with Facebook Api's? I have searched and got few SO posts for taking profile picture of friends like this link1 link2, but I couldn't get anything related to accessing friends photos and getting their images in which they are tagged/ friends face is available.
Can someone help me out on how to accomplish the above case?
See https://developers.facebook.com/docs/reference/fql/photo_tag/
To get links you have to run query like
select link from photo where object_id in
(select object_id from photo_tag where subject=me())
Of courset instead of me() you have to write your friend id.
Note, that
To read the photo_tag table you need the following permissions:
User:
user_photos permissions to access photo tag information that a user is tagged in.
friends_photos permissions to access photo tag information that a friend is tagged in.
BTW you will receive photos on which the person is tagged, but these photos may contain no real image of person.

Facebook Graph API returns question mark picture, post picture is visible on post page directly

I am working on Facebook Canvas application.
Application purpose is to access to user's accounts, collect posts and preview them posts are photo type.
It also allows same user to see other user's posts.
If user is looking other users' posts, preview on some of posts is question mark picture instead of image in post. If user opens post directly to post Facebook page, picture is visible.
I am using Graph API to retrieve pictures from posts for preview.
Current syntax is
https://graph.facebook.com/<OBJECT_ID>/picture?type=normal&access_token=<ACCESS_TOKEN>
I tried to use page access token as well long living user access token.
In both cases I got question mark picture.
My questions are:
Why is it not possible to see real image through application when user gave permissions to pictures?
Is it possible to detect if image is question mark picture?
EDIT
I use OBJECT_ID, not post ID. Preview is for photo posts. object_id in post is picture id, which can be used in pictures Graph API.
EDIT 2
Only Graph API must be used, nothing else.
EDIT 3
These are permissions that are requested from user: "email", "user_photos", "manage_pages", "read_stream", "read_insights", "user_hometown", "user_location", "user_birthday".
get needed permissions (user_photos & friends_photos)
if you want to get users pics(or friends) try fql its much better in my opinion
https://developers.facebook.com/docs/reference/fql/
or graph api & dont forget to get needed permissions
here are two fql examples
SELECT src_big FROM photo WHERE aid IN ( SELECT aid FROM album WHERE owner IN (SELECT uid2 FROM friend WHERE uid1=me()) AND modified_major > 1349374365) ORDER BY created DESC
SELECT src_big FROM photo WHERE owner IN (SELECT uid2 FROM friend WHERE uid1= 100001785452297 ORDER BY rand() LIMIT 0,20 ) ORDER BY created DESC
at last i recommend you to use facebook sdk for your programming language

Why doesn't the Graph API return the newest photos a user has been tagged in?

About a dozen users have complained that my app that fetches photos they are tagged in is not fetching the most recent photos... it is a simple call.
http://graph.facebook.com/me/photos
Is there any way to get the newest photos? Some sort of Order By? Or is there some kind of delay between tags and access via the API?
Any help would be appreciated!
I've seen some goofy stuff going on with the Open Graph API over the last week where objects that belong to a record are not getting returned with a valid API call. My issue went away on its own this weekend.
There is some delay in the best case between when an item gets tagged and it shows up on all the FB servers. The server that is serving your user's page to them will be different than the one serving the Graph API response. In my experience it is usually less than 30 mins, for the update but I've seen it take up to 6 hours.
As far as I can tell, you need to use an FQL call to explicitly order the results you get back.
You can get a list of photos with tags ordered by time by using this FQL query:
SELECT subject, object_id, created FROM photo_tag WHERE subject = USER_ID
where subject is the user id of the user who was tagged, object id is the id of the photo object, created is the creation time (as Unix timestamp), and photo_tag is the FQL table. This will return a list ordered by time with newest first.
From there, you can get the photo url using the object_id like this:
SELECT src, src_big, src_small FROM photo WHERE object_id = OBJECT_ID
which will give you urls to the photo in 3 differen sizes. This uses the FQL photo table.