views:

760

answers:

2

I have a facebook desktop app with some test users all having granted the stream_read & offline access permissions. I can easily retrieve posts to each users' stream & profile. What I cannot do easily is retrieve posts that a user has made to one of their friend's walls.

In fact, this used to work with a rather complex multiquery, but has stopped working now, or is working only intermittently...

Does anyone care to share their method if one exists or discuss what restrictions there might be to this type of complex querying?

+1  A: 

I gave this a try and ran into the same problem I belive but perhaps I can help explain it a little more.

It might be something worth posting in the Facebook wiki talkpage and see if someone from Facebook can shed some light on it unless I'm missing something here.

Anywhere I put USER_ID would need to be filled in with the user you want to search as and F_ID1, F_ID2 are friends ...

FQL #1: should work (in theory)

  • First get a list of all your friends
  • then use that list in the IN clause of the next query
  • filter out to just posts made by the USER_ID
  • make sure the message isn't NULL

FQL #1: No posts are returned

{
"friends":"SELECT uid2 FROM friend WHERE uid1= USER_ID ",

"postsonfriendswall":"SELECT source_id, actor_id, target_id, message FROM stream WHERE source_id IN (SELECT uid2 FROM #friends) AND message != '' AND actor_id = USER_ID "

}

FQL #2: Posts are returned

Strangely however if you limit to just one friend (F_ID1), you will get back posts USER_ID made to their friends wall!

{
"friends":"SELECT uid2 FROM friend WHERE uid1= USER_ID ",

"postsonfriendswall":"SELECT source_id, actor_id, target_id, message FROM stream WHERE source_id IN (SELECT uid2 FROM #friends WHERE uid2 = F_ID1) AND message != '' AND actor_id = USER_ID "

}

FQL #3: No posts are returned

Yet, try to add another friend to the IN F_ID1 & F_ID2 ... no result again ...

{
"friends":"SELECT uid2 FROM friend WHERE uid1= USER_ID ",

"postsonfriendswall":"SELECT source_id, actor_id, target_id, message FROM stream WHERE source_id IN (F_ID1,F_ID2) AND message != '' AND actor_id = USER_ID "

}
Justin Jenkins
simianarmy
I'd be quite interested why I can't seem to get back more then one friend's posts at one time ... so please pass that on if you find out. A vote up on this answer if helpful would be appreciated too :)
Justin Jenkins
simianarmy
A: 

CORRECTION: After further testing, I found that this solution DOES NOT work 100%. It will return some but not all posts that you have made on other walls - I do not know what the limiting factor is - so I consider this an open question.

The partial solution: So, this is the FQL multiquery that generates the wall posts a user makes on friends' walls:

{"query1":"SELECT post_id FROM stream WHERE source_id IN (SELECT target_id FROM connection WHERE source_id = USER_ID)", 
 "query2":"SELECT actor_id, post_id, target_id, message FROM stream WHERE (actor_id = USER_ID) AND (post_id IN (SELECT post_id FROM #query1))"}

The 1st query does a nested select for all the "targets" belonging to a user (friends & apps?) & uses those as the source_id value for a stream query.
The 2nd query uses the post_id's returned from the 1st query to query the stream again this time with the actor_id attribute set to the user's id.

I don't know if ORDER or LIMIT clauses would help returning more recent queries or not - anyone care to confirm?

simianarmy

related questions