FQL search public posts - facebook

I'm trying to do a search using FQL.
Using the Graph API, it works but there are more options using FQL.
Using something like
https://graph.facebook.com/search?q=myquery&access_token=mytoken
it work fine.
I'm looking for the equivalent in FQL.
What query I must write in here
https://api.facebook.com/method/fql.query?query=SELECT%20post_id%2C%20actor_id%2C%20target_id%2C%20message%20FROM%20stream&access_token=mytoken
The query above give me that
Parser error: unexpected end of query
I want to search in all public posts.
I've been looking everywhere but I did not found any solution.
Thanks.

For searching public posts for a string, you need to use the Graph API, and then filter those posts in your script. I don't think searching all public posts is possible in FQL. While FQL is more powerful, it is also more limited.
You are getting an error because you don't have a "WHERE" clause in your query. This is required in FQL.
The limit comes in because you must use at least one indexed column in your WHERE query. For the stream table you must specify either a post via post_id, a user via source_id or filter_key, or a live stream via xid. The indexed fields are marked with a * on the documentation site.
For instance, [this FQL][1]
SELECT post_id,actor_id,target_id,message FROM stream WHERE filter_key = 'others'
AND strpos(message, 'the') >= 0
will get you all posts that show on your access token owner's wall that have not been posted by the owner, with the string 'the' in them. That is the best you can get. If the post isn't visible on their wall, then you won't get the post.
If you try to leave out an indexed field, FQL will throw a 'Your statement is not indexable' error.
[1]: SELECT post_id,actor_id,target_id,message FROM stream WHERE filter_key = 'others' and strpos(message,'the') >=0

Related

FQL: Get comment data WHERE object_id={a known object_id} works, but WHERE id={a known comment XID} does not?

I'm using FQL to get comment data from webpage with a Facebook comment box. I use the graph to get the object_id, then use FQL to get all comments with that object_id. However, if I want to pull data from a specific comment using its id (sometimes referred to as an XID) the FQL returns 0 results.
According to https://developers.facebook.com/docs/reference/fql/comment/ the id should be indexed, so this query should work:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+id={some known XID}
But it doesn't. BTW, THIS query does work:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+object_id={some known object_id}
It is irritating how I can't pull query for comments using time or fromid or anything other than object_id, id, post_id, and parent_id... but in practice only using the object_id returns anything.
has anyone else run into this problem? Is my XID query wrong somehow, or is the id only indexed on certain kinds of comments, and not webpage comments for no inexplicable reason?
This one I managed to solve with trial and error. I had to put the id in single quotes. It's odd, I could query the object_id without putting it in quotes, but not the id. This is sort of what the working FQL looked like, except with a valid access token:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+id='#########_####'
as opposed to:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+id=#########_####
which failed to return any results.
Thanks for being consistent, Facebook :(

Querying all public facebook posts

I need to build an application that will have three input fields for three URLs. Application then needs to search all public posts on facebook and find users who posted that specific URLs. I'm using this code:
$q = "http://www.someurl.com";
$search = $facebook->api('/search?q=' . $q .'&type=post&limit=200');
foreach ($value as $fkey=>$fvalue) {
if(isset($fvalue['from']['name']))
{
echo $fvalue['from']['name']."<br />";
}
}}
This prints out 200 facebook user's names that posted one specific link. But, as I mentioned above, I need to search for multiple URL match. By using this approach, I would need to make three query calls and then cross-reference results and get users that appear on all three result lists. Is there any way to form query to return needed results in just one call? I now that FQL is powerful tool, but I think that it cannot be used for this kind of public queries. Am I really limited only to public graph api? And if that is the case, is it possible to form complex query using only graph api?
EDIT#1:
I tried using following FQL:
SELECT source_id FROM stream WHERE
CONTAINS('http://www.incgamers.com/2013/12/doom-20th-anniversary-today-true-classic')
AND CONTAINS('http://kotaku.com/5917693/ten-years-of-civ-ii-lock-the-world-in-perpetual-war')
AND CONTAINS('http://www.youtube.com/watch?v=1TBxdXm3DP0') limit 200
As I understand, this should return users who have these three links in their fb stream. However, that is not the case. Am I getting this all wrong?
A simpler approach will be to just check the presence of a URL in the message part of the Post. This fql should work:
SELECT message FROM stream WHERE CONTAINS("http://www.incgamers.com/2013/12/doom-20th-anniversary-today-true-classic")
AND strpos(message,'http://www.incgamers.com/2013/12/doom-20th-anniversary-today-true-classic') >=0
Similarly, to search for a post containing all three links you can extend the fql further.
SELECT message FROM stream WHERE CONTAINS("http://www.incgamers.com/2013/12/doom-20th-anniversary-today-true-classic")
AND strpos(message,'http://www.incgamers.com/2013/12/doom-20th-anniversary-today-true-classic') >=0
AND CONTAINS("http://kotaku.com/5917693/ten-years-of-civ-ii-lock-the-world-in-perpetual-war")
AND strpos(message,'http://kotaku.com/5917693/ten-years-of-civ-ii-lock-the-world-in-perpetual-war') >=0
AND CONTAINS("http://www.youtube.com/watch?v=1TBxdXm3DP0")
AND strpos(message,'http://www.youtube.com/watch?v=1TBxdXm3DP0') >=0
it is no longer possible since facebook disabled public post searching in mid December 2013.

a unique combination of fql and graph api

am trying to search the fb posts of a given keyword but need only results with condition of having more than a specific comments count or likes count, i mean the results will only have posts which have a minimum of given value in comments count and likes count.
i tried with many developers but all are saying that its not possible, as the graph api don't offer this kind of method or http call functions.
but what my point is, there will be a possible way to mix both fql and graph and get the results, something like this, but i don't know the exact schema to use.
https://api.facebook.com/method/fql.query?format=JSON
&query=select comments from comment where object_id in
(select comments_fbid from link_stat where url ='http://developers.facebook.com/docs/reference/fql/comment/')
&pretty=1
You can mix Graph API and FQL requests in a single call using batch requests. You have to use the new Graph API url instead of the REST API url you show in your question. You will also need an access_token to get this data.
Facebook does have a comments.count and a likes object for the comment FQL table. That give a numerical comment count you can query against:
SELECT comments, likes FROM comment WHERE object_id IN
(SELECT comments_fbid FROM link_stat WHERE url ='http://developers.facebook.com/docs/reference/fql/comment/')
AND (comments.count > 5 OR likes > 5)

Facebook IN clause in FQL query

I have a big problem with Facebook FQL, if i do
select message from stream where source_id=175102475936031
I can get the correct data, if i do this
select message from stream where source_id IN(175102475936031,etc,etc,etc)
I got a empty JSON, why? is there any alternative to this select? I have to read the messages from multiple events.
Is your problem solved?
"IN" query is a supported feature of FQL. I have tried it multiple times.
Only needs to have:
column indexable
needs to have permission to access data
data should be present for at least one column :P
select message from stream where source_id IN( 175102475936031, etc, etc, etc)
"NOT IN" is not a supported feature of FQL. Ref: http://forum.developers.facebook.net/viewtopic.php?id=1420

Getting user likes of stream items via FQL (posts, comments, pictures, links, etc)

I need assistance in getting user likes of stream items via FQL. I've got some of the likes coming back, but cannot figure out how to get others. For the access_token, every permission is granted.
Let me show you what I've been able to do:
postings I've liked on Page feeds:
fql?q=Select post_id, source_id, message FROM stream where source_id in (SELECT target_id FROM connection WHERE source_id=me() and is_following=1) AND likes.user_likes=1 LIMIT 10
Note: This worked as of mid Dec 2011 when the original question was posted. Now (mid Feb 2012) it is no longer returning anything liked stream content from a page.
postings I've liked of posts that I posted:
fql?q=Select post_id, source_id, message FROM stream where source_id=me() AND likes.user_likes=1 LIMIT 10
Here's what I'm missing
postings I've liked on friends' walls:
fql?q=Select post_id, source_id, message FROM stream where source_id in (SELECT uid1 FROM friend WHERE uid2=me()) AND likes.user_likes=1 & LIMIT 5000
postings I've liked on events' walls:
????
postings I've liked on groups' walls:
????
Here's what I've come up with, as of the time of posting (10-22-2012):
For friends/subscribedto/pages items:
SELECT likes, post_id, actor_id, target_id, message
FROM stream
WHERE source_id IN (SELECT target_id FROM connection WHERE source_id=me())
AND likes.user_likes=1
OR
From 'like' table:
SELECT user_id, object_id, post_id
FROM like
WHERE user_id=me()
But post_id is always null and object_id doesn't exist sometimes when queried via the graph api (i.e. graph.facebook.com/OBJECT_ID )
For links/external objects - There is no direct way to get the facebook post details from this, but it returns a lot of results. Maybe with another query / multiquery looking for these urls in the stream or link tables.
SELECT url
FROM url_like
WHERE user_id=me()
I found a solution using the Open Graph API. Hope this will help you also?
To perform this action you need the users read_stream permission.
Please let me know if my solution works for your requirements.
Because FQL will not be longer supported than V2.0, I would prefer using Open Graph API over FQL.
/*
*
* Count my_user_id likes in wall of user "123"
*
* ex: url = /123/posts
*
* setTimeout to avoid exceed api level rate limit, code 613
*/
function findMyLikes(url,my_user_id,count,callback) {
console.log(url);
FB.api(url, function (response) {
if (response.data) {
response.data.forEach(function (post) {
//console.log(post);
if (post.likes) {
post.likes.data.forEach(function (like) {
if (like.id == my_user_id) {
count++;
}
});
}
});
}
if (response.paging && response.paging.next) {
setTimeout(function() {findMyLikes(response.paging.next,my_user_id,count,callback)},1000);
} else {
callback(count);
}
});
};
I noticed that this solution may take some time, if your are analyzing very long feeds.
For this issue I have still an open question pending : Getting all likes from a specific user on a news wall with fewer graph API calls
https://codereview.stackexchange.com/q/58270/50013?sem=2
#Jeff Sherlock, a partner engineer at Facebook, says here that 'you cannot pull all of the likes of a person using the fb platform. We limit it to actors, movies, sports teams, etc. for privacy reasons.' I know it doesn't make much sense since you can query all kinds of other stuff with the Facebook API. I would suggest you pic Ashton Kutcher and try to query on his like table... Wait, you need his permission ; ]
The problem is that the like table returns a blank post_id for everything. However, it does return an object_id for your likes.
You can put all these object_ids in a comma separated string, then submit a graph API call with ?ids=objectid1,objectid2,objectid3 etc.
This will then return all the objects that it finds. This way you can get the likes for stream items.
It seems to go about 4 weeks back. I can't seem to make it go any further back than this.
As an aside, one thing you will find is that liked comments are also returned as object_ids in the like table. However, there does not appear to be any way at all to find out the object details of these object_ids. Bit of mystery with these ones.
If you read the like table documentation, post_id field has a note which reads :
These post IDs must be queried from the stream FQL table.
Hence when you compare post_id like post_id<>"", it won't return you anything as default result contains blank post_ids. And it seems when you run below query :
SELECT user_id, object_id, post_id
FROM like
WHERE user_id=me()
It returns the pages liked by user and some other stuff but not the feed posts.
As you already want to get likes from stream table, you just want to get post_id from stream table. To get post_id of NewsFeed for a given day, you might want to try below query.
SELECT post_id
FROM stream
WHERE filter_key IN (
SELECT filter_key
FROM stream_filter
WHERE uid=me()
AND type='newsfeed'
)
AND is_hidden = 0
AND description<>''
You might want to use Limit and Created_time fields to get more no. of posts. And once you use above query in Multi-query to get likes for the user, you'll definitely get likes for a given day.
SELECT post_id, actor_id, message, type, permalink, attachment, likes,
comments, description, updated_time, created_time
FROM stream
WHERE filter_key in (
SELECT filter_key
FROM stream_filter
WHERE uid=me() AND type='newsfeed'
)
just change type on your requirement
This is not possible with the GraphAPI. The GraphAPI will allow you to see the pages that a user has liked with /me/likes, but it will not give you a list of all the items posted to the user's wall that they haved liked.
You can see details on this in the Facebook Documentation.
I have no experience with FQL as listed in your question, but a Stack Overflow question seems to provide an answer to your question.
See: Facebook API - "All my likes" query
Worked perfectly in testing.