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

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.

Related

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 :)

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

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

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

Facebook Graph API returns partial results for albums

When pulling photos from a Facebook album via the graph API, i.e.
https://graph.facebook.com/<albumid>/photos?access_token=<token>&limit=999&fields=name,source
For some albums, it only supplies partial results. For instance, an album with 15 photos may only return 13 photos. This call:
https://graph.facebook.com/<albumid>?access_token=<token>&fields=count
...Indeed returns the proper count of 15. My first thought was that perhaps these 2 "missing" photos have more limiting privacy settings, but every photo in the entire album (which is owned by the owner of the token, incidentally) has the same "visible to friends" privacy setting. Most albums do return all photos, as expected.
Any ideas as to what might be causing this behavior?
I was missing 4 photos of 33 for one of my albums. I added 'user_status' to the permissions and it suddenly works.
Instead of the cause of why it happens, I am suggesting you a workaround. Graph api is well known for returning partial results. (You can search for that, and you get hell lot of such issues.)
why not go the FQL way?
Checkout :https://developers.facebook.com/docs/reference/fql/photo/
You can get the id, or direct images links of the pictures in an album in a single query.
Sample : SELECT src_big FROM photo WHERE aid="20531316728_324257"
This returns the url of biggest version of the pictures inside the album.
This should probably solve your problem as long as you are using a user access_token and not app access_token.

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.