Querying all public facebook posts - facebook

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.

Related

getting full number of comments of facebook status in API v2.6

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

Use Facebook API to list group members' join date and inviter

I can use the Facebook Graph API to get a list of group members. The simplest way to do this is to go to the Graph API Explorer and do a GET request of the form {group_id}/members. Is there a way to similarly obtain the members' join date and who they were invited by?
The relevant Graph API doc doesn't seem to mention it. But I know the information is stored by Facebook because it is possible to list all of the group members and their inviters through Facebook itself. Is there a way to get this information through the API?
EDIT: Nothing in the FQL group or group_member API either.
While this information is not available on the API, you can get it by using Selenium to scrape the members page.
First, instantiate a driver and use it to get the members page:
driver.gethttps://www.facebook.com/groups/your group number/members
Then, look for the member information:
containers = driver.find_elements_by_tag_name('td')
Finally, iterate through the web elements, extracting text and parsing resulting list for joined date information:
member_info = container.text.split('\n')
name = member_info[0]
member_since = member_info[-1]
You'll still have to map this information to the user ids, which you can do by looking for another element in the container and using REGEX.
`def parse_id(self, container, name):
hovercard = container.find_element_by_link_text(name).get_attribute('data-hovercard')
regex_id = re.compile('php\?id=(\d*)')
member_id = regex_id.search(hovercard).group(1)
return member_id`
It is indeed stored by Facebook and retrieved for use with internal APIs. For the Graph API however it is not possible to get this information.
All the fields available for a group_member are listed at SELECT column_name FROM column WHERE table_name = "group_member"

fb:comments-count return wrong value

I use
<fb:comments-count href=http://e-drpciv.ro/intrebare/963/></fb:comments-count>
I also try with quotes
<fb:comments-count href="http://e-drpciv.ro/intrebare/963/"></fb:comments-count>
and the return is always zero:
/**/ FB.__globalCallbacks.fdd5cbfe8aa94c({"data":[{"name":"index_link_stat_url","fql_result_set":[{"url":"http:\/\/e-drpciv.ro\/intrebare\/963\/","commentsbox_count":0}]}]});
Some other links report less comments than real.
Eg. http://e-drpciv.ro/intrebare/35 report only 3 comments
I need to update something in my code? Or is just a facebook issue and I need to wait?
This problem persist for two days.
If someone shares someone else story it wouldn't show you the comments of that previous share in your /home, but when you query the fql to get comment_count of that object "SELECT comment_info FROM photo WHERE object_id = 1234567890" it will count you all comments from all shares, this is why when you query the /home with FB API you will find posts without comments but with the SELECT ... it will return you positive number of comment's count. i belive that there is some join to make or to can get only the current user.

FQL search public posts

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

How to get (better) demographics for fans of a Facebook page?

I'm trying to get demographics for fans of a page on Facebook - mostly country and city, but age and gender as secondary.
The primary way to do it is using FQL and doing a query in the insights table. Like so:
FB.api({
method: 'fql.query',
query: "SELECT metric, value FROM insights WHERE object_id='288162265211' AND metric='page_fans_city' AND end_time=end_time_date('2011-04-16') AND period=period('lifetime')"
}, callback);
The problem with this, however, is that the table returns a maximum of 19 records only, both for the country and the city stats. The response for a page I'm testing is as such:
[
{
"metric": "page_fans_city",
"value": {
"dallas": "12345",
"atlanta": "12340",
(...)
"miami": "12300"
}
}
]
So I'd like to know if there's any alternative to that -- to get demographics of the current fans of a page (no snapshot necessary).
Things I've tried:
Using LIMIT and OFFSET on the query do nothing (other than, sometimes, give me an empty list).
One alternative that has been discussed in the past is to use the "/members" method from the Graph API (more here) to get a list of all users, and then parse through that list. That simply doesn't work - a method exists, and it may have worked in the past, but it's not valid anymore (disabled?).
Request:
https://graph.facebook.com/platform/members?access_token=...
Response:
{"error":
{
"type":"OAuthException",
"message":"(#604) Your statement is not indexable. The WHERE clause must contain an indexable column. Such columns are marked with * in the tables linked from http:\/\/developers.facebook.com\/docs\/reference\/fql "
}}
Other solution was to do a query to the page_fan table and filtering by page_id. This doesn't work, either; it may have worked in the past, but now it says that the page_id column is not indexable therefore it cannot be used (same error as above, which leads me to believe /members uses the same internal API that has been disabled). Page_fan query is only useful to check if individual users are fans of a page.
There's also the like table, but that's only useful for Facebook items (like posts, photos, links, etc), and not Facebook Pages.
Going to the insights website about the Page, you can see the data in some nice graphs and tables, and download an Excel/CSV spreadsheet with the historic demographics data... however, it also limits the data to 19 entries (sometimes 20 with a few holes in there as cities trade top positions though).
Any other hint on how to get that data? I'd either like the insights query with more results, or at least a way to get all the page fans so I could do the location query myself later (even if the page I want to get it from has almost 5 million fans... gulp).
The data pipeline for this metric is currently limited to 20 items. This is a popular feature request and something Facebook hopes to improve soon.