Ive been looking for a way to pull recent life events for friends from the graph API but I\'ve ran into a blocker for locations.
I know you can query friends for the
So it turns out the best way to do this is to use FQL against the "stream" table. From here we can add WHERE clauses to do exactly what I'm after. The hardest part is the lack of documentation provided by Facebook on a specific field. "Type".
https://developers.facebook.com/docs/reference/api/user/ https://developers.facebook.com/docs/reference/fql/stream/ Permissions required: "read_stream"
Doing the initial query "SELECT post_id, actor_id, target_id, message FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me() AND type='newsfeed') AND is_hidden = 0" gives you a wide list of updates within your news stream.
So by changing a few things on my test account I was able to find the "type"'s that matched the activity changes on a users account.
Work and Education are grouped.
So say if we wanted to be specific and look for one activity we can change the "type" to be equal to the id's mentioned above.
$query = "SELECT post_id, actor_id, target_id, message, created_time, description, description_tags, type, place FROM stream WHERE type = '62' filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me())";
$response = $this->facebook->api('/fql?q=' . urlencode($query));
The response will look something like this:
'data' => array(
(int) 0 => array(
'post_id' => '100035395_38758242', //I've changed this post id to be random
'actor_id' => (int) 4242, //I've changed this actor_id to be random
'target_id' => null,
'message' => '',
'created_time' => (int) 1347601178,
'description' => 'Joe Smith updated his work and education on his timeline.',
'description_tags' => array(
(int) 0 => array(
(int) 0 => array(
'id' => (int) 4242, //I've changed this id to be random
'name' => 'Joe Smith',
'offset' => (int) 0,
'length' => (int) 8,
'type' => 'user'
)
)
),
'type' => (int) 305, //<--- Note the type id
'place' => null
),
);
Now we need to be aware that Education and Work history can be combined, and potentially other types can be as well. We can from here query the "post_id" directly to get more information related to it.
$post = $this->facebook->api('/100035395_38758242');
The response of this could be something like:
array(
'id' => '100035395_38758242',
'from' => array(
'name' => 'Joe Smith',
'id' => '4242'
),
'story' => 'Joe Smith added Harvid University of America to his timeline.',
'story_tags' => array(
(int) 0 => array(
(int) 0 => array(
'id' => '4242',
'name' => 'Joe Smith',
'offset' => (int) 0,
'length' => (int) 8,
'type' => 'user'
)
)
),
'actions' => array(
(int) 0 => array(
'name' => 'Comment',
'link' => 'http://www.facebook.com/3535/posts/345345' //Changed
),
(int) 1 => array(
'name' => 'Like',
'link' => 'http://www.facebook.com/345345/posts/34534' //Changed
)
),
'type' => 'link',
'created_time' => '2012-09-14T05:39:38+0000',
'updated_time' => '2012-09-14T05:39:38+0000',
'comments' => array(
'count' => (int) 0
)
)
The alternative could be to also query the user id directly and pull fields relevant to the "type". I.e. 'work' or 'education'.
$friend = $this->facebook->api('/242?fields=work,name,education,id');
NOTE: If you require data from X Weeks or Months ago you should use the "created_time" within your queries to Facebook, otherwise you're limited to: 30 days or 50 posts per query.