Facebook graph api to filter feed with text alone - facebook

I want to fetch the group post but i need only text feed from that group. If i call the https://graph.facebook.com/{group_id}/feed? it is fetching all the post in that group.
Ex:
{
"data": [
{
"story": "test 1 created a private event",
"updated_time": "2018-09-03T13:50:25+0000",
"id": "345_543"
},
{
"story": "test 2 shared a post",
"updated_time": "2018-09-03T09:17:44+0000",
"id": "123_321"
},
{
"message": "fetch only feed with this message tag",
"story": "test 3",
"updated_time": "2018-08-31T10:14:12+0000",
"id": "567_765"
},
In this response the 3rd array is the text feed. So is there a way to filter only the text feed from the group.
I know that i can customise it after fetching the result set but i need to implement it with the facebook graph api?

No, there is no such filtering available for the feed endpoint. (No such thing has been implemented, due to performance concerns.)
You will have to fetch all posts, and then filter out what you need/ don’t need yourself on your end.

Related

Facebook Graph API - Get user profile from conversations

by using Facebook Graph API I can fetch the conversations between users and my page. One of the returned conversations looks like this:
{
"message": "message content",
"from": {
"name": "My Page's Name",
"email": "198301820627381#facebook.com",
"id": "198301820627381",
},
"to": {
"data": [
{
"name": "John Doe",
"email": "396169264164870#facebook.com",
"id": "396169264164870",
}
]
},
"id": "m_mid.$cAADurJ0X8UhnJ3tfxVg9jYXJW5fp"
}
I see that I got the user's id field. How can I fetch this user's profile (first name, last name, profile pic) base on this field ? (or is there another way ?)
I followed the Graph API's User Reference but all I got are the user's id and name (which I already have from the returned conversation).
profile_pic only works for PSIDs (Messenger bot events), for ASIDs just use the picture field instead

In FaceBook Graph API v2.4, how can I include pictures/icons of the posts in the JSON feed?

I'm able to get JSON posts feed for a Public Group Page in FaceBook. However, the feed is limited to the following:
{
"data": [
{
"message": "RT Ad Age: Creatives rejoice! The need for speed in digital is putting copy testing under fire http://buff.ly/1NCNUYm",
"created_time": "2015-09-16T19:17:22+0000",
"id": "100893736659527_876911945724365"
},
{
"message": "Smart Design Means Treating Your Users Like Friends.",
"created_time": "2015-09-15T19:17:07+0000",
"id": "100893736659527_876382499110643"
},
{
"message": "Amazon Puts Another Nail in Flash\u2019s Coffin http://buff.ly/1NzwFal (via Digiday)",
"created_time": "2015-09-14T17:25:52+0000",
"id": "100893736659527_875881985827361"
},
{
"message": "Is Belvedere Vodka Good Enough For James Bond?",
"created_time": "2015-09-11T19:17:14+0000",
"id": "100893736659527_874377899311103"
},
{
"message": "RT MailChimp: Our GIPHY integration makes it easy to upload GIFs into your campaign. Exciting, right? http://buff.ly/1JQChqz",
"created_time": "2015-09-10T19:17:14+0000",
"id": "100893736659527_873864092695817"
}
}
I'm able to get the message text, created_time, and id. How can I include pictures/icons of the post?
After #WizKid responded above, this what worked for me: https://graph.facebook.com/v2.4/[page-id]/feed?access_token=[access_token]&fields=picture,id,message

Facebook Graph API Get Comments outside of Wall

I have been learning how the Facebook Graph API works for a while and managed to get the info out of the "me" , "me/likes" and "me/posts" edges,
My question is in regard to the "me/posts" edge; it retrieves all the posts on the user's wall only not the posts/comments he made on another page and or a friends wall, all i get is a "type": "status" JSON node with no actual "message": "" node in the JSON entry saying "XYZ commented on a status."
Example:
{
"id": "<USER_ID>_<POST_ID>",
"from": {
"id": "<USER_ID>",
"name": "XYZ"
},
"story": "XYZ commented on a status.",
"story_tags": {
"0": [
{
"id": "<USER_ID>",
"name": "XYZ",
"offset": 0,
"length": 3,
"type": "user"
}
]
},
"privacy": {
"value": ""
},
"type": "status",
"created_time": "2014-11-11T22:18:25+0000",
"updated_time": "2014-11-11T22:18:25+0000"
}
As you can see there is no "message": "value" node included in the JSON returned its just informing me that he made a comment but i need the value or the message of that comment !
Now, failed attempts i have gone through so far includes:
1. Requesting <PAGE_ID/FRIEND_ID>/posts: I'm unaware of the
PAGE_ID/FRIEND_ID with the information i have from the previous
JSON.
2. Requesting the <POST_ID> returned: As explained it
doesn't work and for my case a 100% of the time.
So is there an official way to know what the user wrote on fan page or on a comment he made on a friend's public wall through the Facebook Graph API or even the FQL API ?
Thanks.
This is a long standing bug in Facebook, probably older than two years.
https://developers.facebook.com/bugs/648986871793611/ https://developers.facebook.com/bugs/522743067756848/
Facebook doesn't seem interested in fixing this.
There is no official way to do this until Facebook fixes the incomplete data.

How to get realtime like count from a picture posted by my app?

I'm developing an application and what I want it to do is:
Post a poto on the user's wall
Get, in realtime, the number of likes that this post will recieve
The first problem I'm having is to get the likes count based on the post-id, this is my photo upload code:
FB.api('/photos', 'post', {
message: $user_submited_string,
url:'http://example/url/image.jpg'
}, function(response){
if (!response || response.error) {
//error handler
} else {
var posted_content_id = response.postid;
console.log(posted_content_id);
})
But when I put this posted_content_id variable into the Open Graph Debugger I won't get the number of likes in return:
{
"id": "1685033176_4107146412059",
"from": {
"name": "João Paulo Apolinário Passos",
"id": "1685033176"
},
"picture": "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-prn1/548929_4107355417284_1018318871_s.jpg",
"link": "https://www.facebook.com/photo.php?fbid=4107355417284&set=a.4107146292056.1073741826.1685033176&type=1&relevant_count=7",
"name": "My Test App Photos",
"icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif",
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/1685033176/posts/4107146412059"
},
{
"name": "Like",
"link": "https://www.facebook.com/1685033176/posts/4107146412059"
}
],
"privacy": {
"description": "Public",
"value": "EVERYONE",
"friends": "",
"networks": "",
"allow": "",
"deny": ""
},
"type": "photo",
"status_type": "added_photos",
"object_id": "4107355417284",
"application": {
"name": "My Test App",
"id": "178883808932511"
},
"created_time": "2013-04-10T01:20:12+0000",
"updated_time": "2013-04-10T01:20:12+0000"
}
Which does not contain the like count of my picture. So the first question is: how to get the like count of the image that the user inserted?
The second thing is that, after getting the number of likes, I want to rank them. To do that, I thought about storing them into a database and set a cron job to check new posts and update the rank with new posts. When I was looking how to do that I came across the "Realtime Updates" section of the Facebook Developers Documentation. But for me it's not clear if I can get this like count in real time and how. And that is my second question: Can I get the number of likes of an image in realtime, using native "Realtime Updates"? And if that's not possible, how to create my own counter? Extended token and cronjobs?
I'm asking this two questions in one because maybe the second question's anwser is also the first one. And the last thing I need to know: even if it's doable, doing something like that violates on someway Facebook Policies?
This is because you are querying for the Post Id, not the Photo Id.
When you upload the photo, a post is also automatically published on the feed of the user.
To read the Photo id, you must use the response.id property.
In your example the id of the photo is 4107146412059, you can derive it from the post id that is in the form <user-id>_<photo-id>, but don't count on it, since that can change in the future.
Doc on the Photo object in the Graph API documentation
Real time updates:
You can get real time push notification from Facebook when the User feed is updated:
but this would be overkill, since you'll get all the posts to the User feed, not only to your photo. Sadly, I think the only way is to poll for updates.
Other info on Real time updates: Facebook documentation

Facebook Ignore Graph API Page Posts Connection - Ignore Replies & Comments? Story vs Message

I'm pulling page posts from the Graph API, but I would like to ignore comments or replies.
So for instance:
{
"id": "115673336230_10151050684306231",
"from": {
"name": "New York Jets",
"category": "Professional sports team",
"id": "115673336230"
},
"story": "\"Well said, Michael. We know our...\" on [User's name removed]'s post on New York Jets's wall.",
"story_tags": {
"40": [
{
"id": ----------,
"name": ------------,
"offset": 40,
"length": 15,
"type": "user"
}
]
},
"type": "status",
"created_time": "2012-09-27T13:39:55+0000",
"updated_time": "2012-09-27T13:39:55+0000",
"comments": {
"count": 0
}
}`
There doesn't seem to be any piece of this response that I can use to filter a reply like this out other than the 'on User's Name post' bit in the story field.
I've noticed that all of the replies to comments appear without message data and with story data, but from the docs its unclear if this would be a reliable data point to filter against.
Is there a way to ignore comments/replies in the Page posts connection? Do all Page Posts (non comment replies) have data in the message field and never in the story field? That is, can I reliably ignore 'posts' that have no message? That have a story?
If you want more powerful filtering, you should look at querying the stream table with FQL.
The type field allows you to filter out posts based on what they are. Adding AND type != 247 will exclude comments from the data returned.
There might be a way to do this using the API by requesting the status_type field, but then you'll have to also manually request all other fields you want to display, and you'll still end up filtering them in your script.