How to retrieve ALL Facebook photos a person is tagged in - facebook

I know you can append limit and offset values to the graph.facebook.com/id/photos API call to paginate through photos. But large limits don't seem to work well, photos end up missing. I read here that limit=0 gives you all photos, but again photos will be missing. So what's the biggest limit you can use reliably? What's the proper way to efficiently retrieve ALL photos?
Is there documentation on the limits of limit?

Here's my experience with the Facebook API...
If you set a limit, you won't get any more than that. However, a large limit will most certainly give you less than you requested despite more existing. All of Facebook seems to run on a principle of "good enough" when it comes to responding to API queries. If you ask for 5000 items and after 5-15 seconds the system is only able to retrieve 350, then that's likely all you'll retrieve. There also seems to be a limit on size of content. So, the limit completely relies on the type of content you're querying and it's not a fixed amount. It's possible to say limit=5 and only get 4 items (even when more exist).
limit=0 used to give as many responses as possible, but I'm not sure if it still works. You can also use since/until to be more specific about the items you want to retrieve. But regardless, there's no way to know if you've gotten all possible responses.

I faced the same issue in our application. "me/photos" doesn't give complete data. One can understand the permission associated with photos but then also "me/photos" end up not returning even photos with "public" permission.
We were able to resolve this issue by taking following approach. Now our application returns all tagged photos except the ones having restrictive permission.
First we did find the list of IDs of photos in which user is tagged using FQL. This can be achieved as following.
FB.api({
"method": 'fql.query',
"query": 'select object_id from photo_tag where subject=me()'
}
,function(resp)
{
}
The above API will give the IDs of photos in which user is active. Now once the ID is available the details of photo can be fetched as following.
FB.api({
"method": 'fql.query',
"query": 'select object_id from photo_tag where subject=me()'
}
,function(resp)
{
var photoId = resp.object_id;
FB.api("/" + photoId, function(data){////DO THE PROCESSING/////////////});
}
The above process involve larger number of requests to Facebook, but till now this is the only way that we have found out to fetch all possible tagged photos.

Related

Facebook graph API: Filter status from feed

I use
http://graph.facebook.com/cocacola/feed?access_token=MY_APP_TOKEN
This works but I would like to exclude the status updates from the result and only get links,photos and videos. There seems to be a filter function as listed here: https://developers.facebook.com/docs/graph-api/reference/v2.0/user/feed
But I don't get how to use it :-(
...cocacola is just an example of course...
I also couldn't get it to work with the Graph API itself, because the docs lack (again) details on how to use it.
You can use FQL to achieve what you desire instead:
select post_id, message, attachment from stream where source_id=me() and type in (80,128,247) limit 50
This will return your 50 most recently posted links, videos and photos. Remember that you'll need read_stream permissions if you access user info. For public page posts, this should be fine without.
Try it: https://developers.facebook.com/tools/explorer?fql=select%20post_id%2C%20message%2C%20attachment%20from%20stream%20where%20source_id%3Dme()%20and%20type%20in%20(80%2C128%2C247)%20limit%2050%0A%0A
To change the subject of the query, change the source_id object_id. For CocaCola, this would be 40796308305 (https://developers.facebook.com/tools/explorer?method=GET&path=cocacola%3Ffields%3Did&version=v2.0).

Facebook FQL posts limit issue

Currently i am using following FQL query :-
https://api.facebook.com/method/fql.query?query=select post_id,likes FROM stream WHERE source_id=XXXXXXXX LIMIT 0,10000&access_token=XXXXXXXXXXXXX&format=json
I have two Facebook Accounts / pages & able to download data using above API. Able to retrieve posts & post likes count.
But, from last three days, for one Facebook account above FQL query is not working. it is returning message :- "error": "Request failed" . For other account it is working fine.
For each facebook Account / pages i have generated separate Access Tokens.
But, if i update limit from : -
Limit 0,50
Limit 50,100
then it is working & returning posts from page but not returning all post which i have previously getting from Limit 0,10000
Please help me, if any one have idea about this issue ?
Thanks
Facebook will cancel queries which take too long or too many resources to execute. In general, I would never use LIMITs which are that high. There's a high probability that they will fail, and you can't really incfuence the query execution "load" other than setting the LIMIT to a reasonable number (which means implementing a paging mechanism).

Multiple stream_filters /me Facebook graph API?

I'm attempting to do some complex Facebook graph queries. I want to retrieve a user's timeline only from specific apps. Here's what I have:
https://graph.facebook.com/me?fields=home.filter(app_2915120374).limit(20).fields(...)&access_token=...
So that works great, however, what if I want to do multiple apps? Providing multiple filters inside .filter() outputs an error.
https://graph.facebook.com/me?fields=home.filter(app_2915120374,app_2305272732).limit(20).fields(...)&access_token=...
{
error: {
message: "(#606) Invalid filter_key app_2915120374,app_2305272732",
type: "OAuthException",
code: 606
}
}
I'd rather not perform multiple requests, since that can take awhile. And, plus, it's not one unified feed. Ex: if I pull 20 statuses, then 20 photos, there will be some gaps in the timeline.
And NO, I don't want to use FQL.
I tested a little, and I assume that you can only pass one stream filter at once. This would also be consistent to the docs at https://developers.facebook.com/docs/graph-api/reference/v2.0/user/home/ stating that
Retrieve only posts that match a particular stream filter. Valid
filters to be used here can be retrieved using the FQL stream_filter
table.

Convert any facebook URL into a graph ID

Is there a simple, reliable and potentially future-proof way to extract a graph ID from the API given any facebook URL? By "any facebook URL" I mean the URL for a personal profile, page, group, etc. All these things have various formats so I imagine there must be something in the graph API to definitively convert a facebook URL into an ID, right?
No, there isn't a way to do this simply within the API. You will need a set of pattern matching to match the various types of urls to extract either the id (album,note,photo,status) or username.
For example
Photos
facebook.com/photo.php?fbid=10100213582161431&set=p.10100213582161431&type=1&theater
https://graph.facebook.com/10100213582161431
Posts
facebook.com/zuck/posts/10100210345757211
https://graph.facebook.com/10100210345757211
Pages
facebook.com/pages/Joel-Spolsky/106083232757300
graph.facebook.com/106083232757300
Videos
facebook.com/video/video.php?v=10150398154330484
graph.facebook.com/0150398154330484
Events
facebook.com/events/138745136241434/
etc ...
Then it gets further complicated that even if you were able to get a silver bullet function that handles all these links your app would need to grant access to numerous permissions in order to access certain objects.
You may be able to get away with most links that have the id at the end but not all. So you can maybe use a regular expression catching links that end in numeric characters.
There is! You are looking for the object_url table, which you can query using FQL or directly with a request. See here: http://developers.facebook.com/docs/reference/fql/object_url/
EDIT:
You can also do this, but obviously less optimal:
function getObjectByUrl(url, cb) {
FB.api("/" + url.replace(/^.*?www.facebook.com/, ""), cb);
}

In the Facebook API, how can I retrieve the source object from a notification object?

Since notifications are not available in the Facebook Graph API, I am using FQL to retrieve them, as detailed at https://developers.facebook.com/docs/reference/fql/notification/.
What I would like to do is use the information returned to fetch the "source object". So if the notification is "Bob commented on your status", I want to find that status object - and if Bob comments on my Note, or posts to the Wall for my Event, etc.
notification_id, sender_id and recipient_id alone don't seem to be enough information to achieve this. The href field is tantalisingly close - it'll return a link that a user can click on to be taken to the appropriate page, but that doesn't look like much help to me as the URL format varies wildly between "source object" types. I can't find a reliable way to turn href into a parameter I can pass to the Graph API.
So, if what I want to do is possible, what's the best way to do it?
My thoughts:
Is there a way to give the "user-friendly" href to an API and have it return the appropriate Graph API results (or have it return the appropriate Graph API URL)?
Is there another way the information returned by an FQL 'notification' query can be used or combined to make a proper Graph API URL?
Is there another way of retrieving notifications that will give me what I want?
I'm using PHP and Facebook's PHP SDK, though this doesn't look like a PHP-specific issue.
Thanks in advance!
You can get object_id, object_type from the notification table and use that to fetch the original post. Sorry, this wasn't documented in the 'notification' table, but is documented now.
E.g.:
select object_id, object_type from notification where recipient_id=<user_uid>
which returns something like:
[
{
"object_id": "<object_id_1>",
"object_type": "group"
},
{
"object_id": "<object_id_2",
"object_type": "stream"
},
]
and you can then use the object_id to fetch the post:
https://graph.facebook.com/<object_id_1>?access_token=<access_token>

Categories