i want to have facebook comments + my own website comments on my site.
The thing is when showing posts i want to show a comment count next to every single one(so my comments + facebook comments).
I know i can achieve this with https://graph.facebook.com/comments/?ids={PAGE_URL} but i have 100posts per page and i don't want to do this query a 100 times per page, also and more important is that i want to create a most commented widget where i currently have 1/4 of a million (250000) posts.
So basically my question is how i can access sort of a database on all comments left on my domain/site and sort them, that is manipulate them?
Here are some examples of ways you could do this:
FQL:
You can build your a JSON array of queries and then use the Rest API fql.multiquery method to run them. For example, this would be your JSON array of queries:
{
'query1': "select post_fbid from comment where object_id in (select comments_fbid from link_stat where url ='http://developers.facebook.com/docs/reference/fql/comment/')",
'query2': "select post_fbid from comment where object_id in (select comments_fbid from link_stat where url ='http://developers.facebook.com/docs/reference/fql/album/')"
}
Run this using the test console on the fql.multiquery page and you'll be able to see a response containing a list of post_fbids which you could then count using your favored counting method.
Graph API:
Here you can use a Batch Request to run all of your queries at once. So for a PHP Example you'd be doing:
curl \
–F ‘access_token=…’ \
-F ‘batch=[ \
{“method”: ”GET”, “relative_url”: ”comments/?ids={PAGE_URL1}”}, \
{“method”: ”GET”, “relative_url”: ”comments/?ids={PAGE_URL2}”}, \
{“method”: ”GET”, “relative_url”: ”comments/?ids={PAGE_URL3}”} \
]’\
https://graph.facebook.com
For as many pages as you want.
Note: Given that both APIs do have a bit of a delay before you'll get a response, obviously it's recommended to run them asynchronously so that you aren't causing your site load to delay significantly.
Try this:
Place the URL separated by commas, If you wanna fetch multiple calls using the graph API :
https://graph.facebook.com/comments/?ids=http://URL_1,http://URL_2,http://URL_n
I think for your use case FQL will suit the best : https://developers.facebook.com/docs/reference/fql/comment/ .
On the side note, if you wanna do multiple http calls using the graph API , its always good to do "Batch calls" as documented in the graph API documentation.
Related
How to get number of all comments (number of status comment + number of comments of comments) without looping over every comment?
This parameters show only number of direct comments of status, without nested comments
?fields=comments.summary(true).limit(0)
How to do it similarly to FQL?
FQL requests have no problem with it
SELECT id,likes,post_fbid,time,fromid,text,text_tags,parent_id FROM
comment WHERE post_id = %post_id%
it returns all comments (nested or not) as is. easy to count and easy to check of something changed
Found an answer: you should use filter = stream
likes this
?fields=comments.summary(true).filter(stream).limit(0)
It's in the official documentation, but was not very obvious to me, that it can be used in object endpoint and not only in object/comments.
https://developers.facebook.com/docs/graph-api/reference/v2.6/object/comments#readmodifiers
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.
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)
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
i am usig Facebook fql.multiquery to fetch data with command line. like this
$queries = '{
**"query1" : "SELECT metric, value
FROM insights WHERE object_id=148945955209922
AND metric="application_active_users"
AND end_time=end_time_date("2011-12-10")
AND period=period("month")",
"query2" : "SELECT metric, value
FROM insights WHERE object_id=148945955209922
AND metric="application_active_users_city"
AND end_time=end_time_date("2011-12-10")
AND period=period("month")"
}';
But while running this code it is showing empty Array.
can anybody help me?
I would first start troubleshooting your access token. Ensure your access token has the appropriate permissions. Secondly, ensure the queries run independently of each other by running each one separately thru the normal FQL. You can play around with the FQL structure using the Graph API Explorer tool https://developers.facebook.com/tools/explorer