2

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:

  1. 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)?

  2. Is there another way the information returned by an FQL 'notification' query can be used or combined to make a proper Graph API URL?

  3. 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!

1 Answer 1

3

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>
2
  • This question is old, sorry. When we query /me/notifications we get batch items like "Person1, Person2, and 11 other people sent you requests in CoolApp". The link in that contains the IDs of maybe 8 requests, which I imagine is short simply because there is a limit on the length of a URI/querystring. Is there any way to get all of the requests as separate object requests? As I said, not all of the request IDs are in the link. I've tried FQL queries like this with no good results: SELECT recipient_uid, request_id, app_id FROM apprequest WHERE recipient_uid=00me00 AND app_id=11app11
    – TonyG
    Dec 7, 2011 at 4:46
  • I should mention as well that the object_id for apps is an empty string, so we can't use that to get app_data or anything else from posts with the stream table. My goal is described in another thread. Perhaps @vikas-gupta knows about this? Thanks.
    – TonyG
    Dec 7, 2011 at 4:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.