I'm writing a facebook app that iterates through comments.
I can get the user status and their comments:
$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => APP_SECRET,
));
$statuses = $facebook->api('/me/statuses/?token='.$session['access_token'],'GET',$params);
In the same way I can get the user posts:
$posts = $facebook->api('/me/posts/?token='.$session['access_token'],'GET',$params);
I was wondering if there's a way I can get the comments from the user's relationship change
(user went from being single to being in a relationship)
Those relationship status changes aren't currently available via the Facebook API, thus the comments attached to them are not either. Having this available via the API has been requested hundreds of times, I don't know why they don't have it.
This info can be accessed. Relationship status updates can be seen with the following permissions: user_relationships
and read_stream
. To extract the exact story(and associated comments) however you'll have to parse through the result, and a relationship update looks like this:
{
"id": "10000xxxxxxxxxx_2yyyyyyyyyy",
"from": {
"name": "Foo Bar",
"id": "10000xxxxxxxxxx"
},
"story": "Foo Bar went from being \"in a relationship\" to \"single.\"",
"story_tags": {
"0": [
{
"id": 10000xxxxxxxxxxx,
"name": "Foo Bar",
"offset": 0,
"length": 9,
"type": "user"
}
]
},
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/10000xxxxxxxxxx/posts/2yyyyyyyyyy"
},
{
"name": "Like",
"link": "http://www.facebook.com/10000xxxxxxxxxx/posts/2yyyyyyyyyy"
}
],
"type": "status",
"created_time": "2012-05-05T07:36:32+0000",
"updated_time": "2012-05-05T07:36:32+0000",
"comments": {
"data": [
{
"id": "10000xxxxxxxxxx_2yyyyyyyyyyy_7zzzzz",
"from": {
"name": "Foo Bar",
"id": "10000xxxxxxxxxx"
},
"message": "YaY",
"created_time": "2012-05-05T07:45:31+0000"
}
],
"count": 1
}
},
When there are two users concerned in the story(say : XXX is in a relationship with YYY) then the 'story_tags'
field will have the tags containing the other user's id too.
I think there are no updates for divorced, separated, widowed (not sure).
Other relationship updates could be (not exhaustive)like:
Alice is in a relationship with Bob and it's complicated.
Alice is in an open relationship with Bob.
Alice is single.
So to extract the update, there have to be two conditions met: the field 'story'
should exist and it should contain one of the keywords relationship, single, engaged or married.
Once you have the story/post id, it's easy to extract the comments.
Api call :
https://graph.facebook.com/me_or_id/feed
https://graph.facebook.com/me_or_id/posts
Api call : https://graph.facebook.com/me_or_id/statuses
did not give the desired result, even with user_status
and user_relationship_details
permissions.
AFAIK this is the only way, at the moment.
Edit: FQL way:
In fql we can query the stream table. In the documentation it is mentioned that each post has a description field which is not null if it is an auto-generated post, i.e not made by the user, for example users becoming friends, or relationship changes. Other posts have a message field (and a null
description field). This description field, i believe is analogous to the story
field for the graph api method. And such auto generated posts will have their type
set to 9, which is not mentioned in the documentation, (explanation for type is there but not for type 9). Anyway we can make a restrictive query with these additional conditions and hope to get the correct data, which we might still have to parse to remove other stories, but atleast the data to parse through will be less.
Query:
SELECT post_id, type, description, comments FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me() AND type='newsfeed') AND is_hidden = 0 AND type = 9
You'll have to parse the description field again for the keywords mentioned before.
Note: for some reason i couldn't get the comments with this one query (the comments array was always empty), but when i called the graph api with the post_id
from the query result, i could get the comments.