Graph API SEARCH not returning public posts done on a page - facebook

I'm trying to get posts with a certain keyword (in fact, a hashtag), but I'm not receiving all posts. For example, there are a lot of posts done by users on a certain page that are not being pulled although they're public. The call I do is similar to this one:
https://graph.facebook.com/search?type=post&q=keyword&access_token=XXXXX
Not sure if this type of posts are considered public but only retrievable by specifying the page:
https://graph.facebook.com/PAGE_ID/feed?access_token=XXXXX
But I need to retrieve all public posts containing a certain keyword and I don't know exactly which pages could users post to with this hashtag...

Be aware that Facebook has just taken down public post search in Graph API v2.0 so you won't be available to do that anymore.
Check https://developers.facebook.com/docs/apps/upgrading under section Graph API "Public post search is no longer available. (/search?type=post&q=foobar)"

Related

Extracting public data from Facebook in a legal way

I want to make an application that needs to collect some public data from facebook.
Specifically I need to check reactions and comments made on public posts.
I've noticed two things:
First, According to https://www.facebook.com/apps/site_scraping_tos_terms.php,
scraping is not allowed unless facebook gives you a written permission. (of which how do I ask for permission anyway?)
Second, as far as I see the graph api doesn't allow to get information regarding posts made by another user/page. Am I wrong?
How do I get the information I need in a legal way and is it even possible?
To get public posts in a page and reactions and comments on these posts your app will need will need Page Public Content Access permission. If you have not already created the app, you can find how to do this in this link and how to review your app for permissions in this link.
Once you have the permission you can get public posts from a page using below API request:
https://graph.facebook.com/<PAGE_ID>/posts?access_token=<ACCESS_TOKEN>&fields=name
Get the id of posts you need details for from the response of the above request
Then you can use the below request's to get reactions and comments of the post based on the post id
Get total reactions:
https://graph.facebook.com/<POST_ID>?fields=reactions.summary(true)&access_token=<ACCESS_TOKEN>
Get total reactions of a specific type (NONE, LIKE, LOVE, WOW, HAHA, SAD, ANGRY, THANKFUL, PRIDE):
https://graph.facebook.com/<POST_ID>?fields=reactions.summary(true).type(<REACTION_TYPE>)&access_token=<ACCESS_TOKEN>
Get comments:
https://graph.facebook.com/<POST_ID>?access_token=<ACCESS_TOKEN>&fields=comments.summary(true).limit(999).filter(stream).fields(id,message,created_time,parent)
And as for public posts by a user you will be able to get the total reactions with the same request by providing the post id if the post is public, but you cannot get the comments, however you will get the comments count

Getting Facebook comments "From" field using Graph API [duplicate]

Recently, when using the /feed Facebook Graph API method, it has stopped returning the From field. This field typically contains the Id and Name of the author of the Facebook Post in question.
The URL I'm hitting is https://graph.facebook.com/{id}/feed?fields={my-fields-here}&access_token={token}
From what I can tell, the From field still exists within the API: If I try https://graph.facebook.com/{id}/feed?fields=id,from&access_token={token} I get a list of IDs (no Froms though), without errors.
However, if I try a deliberately-invalid field name, such as https://graph.facebook.com/{id}/feed?fields=id,doesnotexist&access_token={token} then I get an error response of (#100) Unknown fields: doesnotexist.
So the From field still exists as far as the Facebook Graph API is concerned. It's just no longer being returned. Did something change recently? The From field is also still listed as the list of fields over on their documentation. As far as the data itself goes, posts dating months back also no longer have From, so it's not a case of "newer posts in the feed lack the field, but older posts do either."
I'm at a loss! If anyone could lend a hand, I'd appreciate it.
It is only included if you use a Page Token. v2.11 of the Graph API (90-Day Breaking Changes):
/page/* — User information will not be included in GET responses for
any objects owned by (on) a Page unless the request is made with a
Page access token. This affects all nodes and edges that return data
for objects owned by a Page.
Source: https://developers.facebook.com/docs/graph-api/changelog/version2.11
...or in the link of your question:
Any valid access token can read posts on a public Page, but responses
will not include User information.
A Page access token can read all Posts posted to or posted by that Page, and responses will include User information.

Get Share Count of Public Video with FB API v2.5

The Short Version:
"I can visit the public page without being logged into Facebook and see underneath the post is says "2155 shares" I would like to know how to access that number through the API"
The Details:
I'm trying to use the newest version (v2.5) of the graph HTTP API to determine the total share count for a public video. The problem is FB seems to have changed the API enough that older posts on SO no longer answer this question.
Looking at the Graph API Documentation it appears that video nodes now have the "sharedposts" edge. However, calling this route with summary=true only returns a few of the shares and no value for a total count. This returns counts for comments and likes so I'm not using the endpoints incorrectly or messing up my authorization.
I've also tried to use the URL Node but this doesn't seem to do much with links inside of Facebook. I simply get a JSON response with an 'id' field with the same url I supplied as a request parameter. Seems like this route is meant to be used for links to content outside of Facebook.
I've tried the above methods with multiple videos on multiple public pages so I don't think it is due to the group owners restricting access, unless this is the new default.
It seems arbitrary that I would be allowed access to total counts for comments and likes, but not shares. Is there some legacy way to do this or am I out of luck for now?
You should query the Post element containing the Video element.
Each video posted is also contained in a post element.
The post id is then composed of the video id prepended with the posting entities id (user, page etc'), separated with an underscore.
It then looks like: user-id_video-id.
Then using the Graph API to get the share count of a post is straightforward:
GET /v2.5/{post-id}?fields=shares
Example
Lets take a video from the BBC page:
https://www.facebook.com/bbcnews/videos/10153524838517217/
(Please tell me if the link is broken. I'll switch it to something newer :))
Video id : 10153524838517217
Page id (see below): 228735667216
--> Post id: 228735667216_10153524838517217
And the request would be:
GET /v2.5/228735667216_10153524838517217?fields=shares
(open in the Graph API explorer)
Page id
to get the page id, you could query the video element for the from field.
GET /v2.5/10153524838517217?fields=from

How to get top global public posts with most number of likes from facebook using fql

I want to get top global public posts from facebook with most number of likes using fql, is there anyway to do it?
I am able to get the posts for a specific page and actor.
SELECT message, likes.count, attachment FROM stream WHERE
source_id='SOURCE_ID' AND actor_id= 'ACTOR_ID'
but is there anyway like using queries like max(likes)
Short Answer: No
FQL is deprecated
Public Post Search is deprecated
Public Feed API is restricted to a limited set of media publishers and you cannot apply (at least not right now)
Links:
https://developers.facebook.com/docs/apps/changelog
https://developers.facebook.com/docs/public_feed

Facebook Search API, keyword search does not display posts made in a page but only in a profile

I am using the facebook search API to find posts that include my keyword. I noticed that the posts returned always belong to facebook profiles but never facebook pages. To back that up, I searched for keywords of low frequency which I spotted in pages but the API did not return them.
Is there any way I can search by keyword and get posts from pages too ?
Taking a look at the documentation: Just search with &type=post. From that documentation:
All public posts: https://graph.facebook.com/search?q=watermelon&type=post