Get (Identify) Replies to Comments Using the Graph API - facebook

With the new "Reply" to "Comments" feature on Facebook, I've noticed that replies to comments are treated the same as comments. But I was wondering if there is anyway to distinguish the two?

You first have to enable July Breaking Changes from your app advanced settings
Then use the fields parameter with the comments graph API and include the parent.field(id) column with the and also the filter parameter with the stream value. the final result :
{POST_ID}/comments?filter=stream&fields=parent.fields(id),message,from,likes
this should return both comments and replies with the parent element which has the comment id that the reply belongs to
-- update
and for better array arrangement for replies you can use the following to merge replies with the actual comment array you can include comments.summary(true) in the fields parameter
{POST_ID}/comments?limit=0&filter=toplevel&fields=comments.summary(true),message,from,likes
filter parameter is optional
for more info about the fields : http://developers.facebook.com/docs/reference/api/Comment/
and in case you want to do it in FQL, check this post's comments http://developers.facebook.com/blog/post/2013/04/03/new-apis-for-comment-replies/

Yes. You can query each comment object in the Graph API for the value of its parent field. If the comment in question is a reply, then the value of the parent field will be a reference to the parent comment. Otherwise, no value is returned.
Reference here: https://developers.facebook.com/docs/reference/api/Comment/

You can get comment replies in this way.
/{{POST_ID}}/?fields=comments{comments}&access_token={{ACCESS_TOKEN}}
You can get any sub info(from,id) of comment replies by just nesting fields inside comments like this:
/{{POST_ID}}/?fields=comments{comments,from,id}&access_token={{ACCESS_TOKEN}}
Similar post over here :
https://stackoverflow.com/a/37743410/6001533

If you're listening for comments on the 'feed' webhook, you should check if:
entry[0][changes][0][value][post_id] === entry[0][changes][0][value][parent_id]
This will be true for top-level (new) comments, and false for replies to comments.

To piggy back off #sujit's answer I took his answer and in one call from the feed you can get the entire feed, comments and replies to comments as well as associated images to those comments and replies in one shot.
Here is the code
https://graph.facebook.com/$get_facebook/feed?access_token=$facebook_accesstoken&client_id=$facebook_appid&client_secret=$facebook_appsecret&metadata=1&fields=id,status_type,created_time,from,message,comments{comments{attachment,from,id,message},from,id,message,attachment},picture,link,icon

Related

Mongo conditional find

So I have this article page and I need to place related articles below the current article body.
There are certain attributes that I use to find similar articles but in case there isn't any, or if there is less than 2 found, I need to add just some other articles to the result.
So if a given article has a tag "Development", I need to search for 2 other articles with that tag, and if there is less than 2 that have this tag, I need to pull just some other articles.
Right now the flow is:
I make a request to get an article using query
I make request for related articles using the result of the first request.
But now I have difficulty understand how to make another request or put a condition into the second request to optimally get another article(s).
I appreciate any help
const article =await "your collection". find({tag:"Development"}).limit(2);
const x=2 - article.length
while(x>0){
var y=await "your collection". findOne();
article.push(y);
x--;
}

Stack Exchange API - getting answers for the questions object

I use https://api.stackexchange.com/docs. To get a sample question, I use the address https://api.stackexchange.com/2.2/questions/6827752?&site=stackoverflow. Thanks to this, he gains a question. The following page shows https://api.stackexchange.com/docs/types/question that with the default filter the question will not have a body. I know I use a filter to get a body filter=withbody that is, the address comes out
https://api.stackexchange.com/2.2/questions/6827752?&site=stackoverflow&filter=withbody
Now I would like to get answers for the question. That's why I want to use a filter filter=withanswers. This address
https://api.stackexchange.com/2.2/questions/6827752?&site=stackoverflow&filter=withanswers
returns an error
{
"error_id": 400,
"error_message": "Invalid filter specified",
"error_name": "bad_parameter"
}
How do get answers or comments using a filter?
I think that 2 patterns can be thought for your solution. One is a method using custom filter. Another is a method using the endpoint for retrieving answers.
Pattern 1 :
You can create a custom filter for retrieving answers and answer's body using the endpoint of https://api.stackexchange.com/2.2/questions/### questionId ###.
You can create the custom filters at http://api.stackexchange.com/docs/create-filter.
In your case, you can use this.
question.answers;answer.body;question.body was used as including filters.
The delimiter is ;.
As a result, you retrieve "filter": "!T*hPNRA69ofM1izkPP".
When you use the filter, please do URL encode it.
!T*hPNRA69ofM1izkPP becomes %21T%2ahPNRA69ofM1izkPP.
You can retrieve answers and answer's body using the endpoint.
When the question ID of your question is used, it's https://api.stackexchange.com/2.2/questions/6827752?&site=stackoverflow&filter=%21T%2ahPNRA69ofM1izkPP.
Result of pattern 1
When you can access to https://api.stackexchange.com/2.2/questions/6827752?&site=stackoverflow&filter=%21T%2ahPNRA69ofM1izkPP, you can get answers and answer's body.
Pattern 2 :
As the endpoint for retrieving answers, you can use /questions/{ids}/answers. If the question ID is 6827752 in your question, the endpoint is as follows. In this case, in order to retrieve answer's body, filter=withbody is used.
Result of pattern 2
When you can access to https://api.stackexchange.com/2.2/questions/6827752/answers?order=desc&sort=activity&site=stackoverflow&filter=withbody, you can get answer's body.
If this was not useful for you, I'm sorry.

Unable to retrieve 'ContentId' property of Attachment in Office365 REST Api

I'm trying to retrieve attachments in the Office365 rest api. Since I want to avoid downloading the entire attachments, I'm using a select clause to avoid downloading the content, which is in the ContentBytes property:
$select="ContentId,ContentType,Id,IsInline,Name,Size"
So basically, I want to retrieve everything except the content. However, this gives the following error message (json):
{
"error":
{
"code": "RequestBroker-ParseUri",
"message": "Could not find a property named 'ContentId' on type 'Microsoft.OutlookServices.Attachment'."
}
}
It's telling me that ContentId doesn't exist, which contradicts the specifications.
Edit: Here is the full request:
GET /api/v2.0/me/messages/AAMkAGZlZjI3N2I3LTg1YWUtNDFiNC05MGI0LTVjYTVmZGI5NGI2YQBGAAAAAABzr8uDji9LRqgTCEsDv22wBwBWTXbvZW0dTKuxUGxpK4-lAAAAAAEMAABWTXbvZW0dTKuxUGxpK4-lAAC5QnKBAAA=/attachments?%24select=ContentId%2CContentType%2CId%2CIsInline%2CName%2CSize
Even more strange, when I do the same query without specifying any select clause, it returns me a full attachment object, including a ContentId.
Anybody can help?
In case anyone has the same question for microsoft graph, you need to pass this filter:
$select=microsoft.graph.fileAttachment/contentId
like this:
GET https://graph.microsoft.com/v1.0/me/messages/attachments?$select=microsoft.graph.fileAttachment/contentId
The request that you posted is getting the message specifications but not the attachments. Since you need to get the content id, you need to add /attachments to the request with any required parameters.
GET https://outlook.office.com/api/v2.0/me/messages/{message_id}/attachments/{attachment_id}
So please add the attachments to your query to be able to get the content id.
Hope this helps.
Solved it. The answer was suggested by Brian's comment and I found an additional hint here.
Since 'ContentId' is a property of a FileAttachment, you need to specify that in the request, like so:
$select="Microsoft.OutlookServices.FileAttachment/ContentId,ContentType,Id,IsInline,Name,Size"
That did the trick. Thanks for the suggestions.

Facebook Graph API event-id/comments?since=2014-02-01&until=2014-02-10 , Date filter has no effect

I am trying to bring comments made on a particular event by targeting this URL: https://graph.facebook.com/1466384840257158/comments
I am passing the user_access_token
I have two comments at present on this event made on the same
day(2014-03-29)
Now I try to pass a date which should bring an empty data result/object
like this: https://graph.facebook.com/1466384840257158/comments?since=2011-01-01&until=2014-01-10
This request has no effect, it still shows me the two comment made
on the 29th
I have tried the same kind of date range on my user-id/feed and it
gave me an empty data object.
Finally i tried event-id/feed (before trying date filter) and it
gave me the following error
.
{
"error": {
"message": "An unexpected error has occurred. Please retry your request later.",
"type": "OAuthException",
"code": 2
}
}
Could you please guide me about date filter on that particular query (point4) or if you have any other idea to use date filter on comments made for an event.
Comments use Cursor-based Pagination, so you cannot use since or until on the comments endpoint (these parameters would work f.ex. for the feed endpoint).
To get the comments in a time range you have to fetch all comments from NOW to the start of the time range, f.ex. with https://graph.facebook.com/1466384840257158/comments?filter=stream&limit=1000+paging (the filter=stream will order the result with the timestamp).
USING SINCE UNTIL FOR COMMENTS on GROUP
If you want to use since and until for comments, it is not possible directly for a group. So, First you can apply it for status(feed) and then get the comments for that feed.
This works for me:
{group_id}/?fields=feed.since(08/25/2016).until(08/31/2016){from,comments{from,message}}
Why don't you try first to filter by notifications?... notifications allows you to add parameters like since. For example (using Facebook pages):
https://graph.facebook.com/PAGEID?fields=notifications.since(2015-3-31 00:00:00).limit(250).include_read(true)&{id,created_time,updated_time,unread,object,link}&access_token=ACCESSTOKEN
Once you got the json data, loop through data, get the ID and send a second request but this time using the PAGEID_POSTID edge. Something like this:
https://graph.facebook.com/PAGEID_POSTID/comments?fields=id,from{name,id},message,can_remove,created_time&limit=1000
Voahla!... there's no need to read every comment!...
Note 1: A Page access token is required, along with the manage_pages permission
Note 2: Use the parameter/field include_read to get all the notifications, even the already readed
Note 3: In the second request, use the parameter/field "filter=stream" to order the posts and get the comments made in the name of your page
Note 4: Don't forget to control the asynchronicity once you loop!
Note 5: Notifications duplicate posts, use an array to avoid to read more than one time the postUse the parameter/field include_read to get all the notifications, even the already readed
I do not know if it's too late. But, Yeah it works in the graph api version 3.3.
for example: if you wanna get comments on a post of a Facebook page you can do it like this:
You have to use page Access-token
The get Graph Request : post_id/comments?since=some_date

What do the keys in Facebook's 'data-ft' JSON structure represent?

On Facebook pages, many HTML elements include a 'data-ft' JSON object that is of the form:
data-ft='{
"src":10,
"sty":263,
"actrs":"117307284966434",
"targets":"117307284966434",
"pub_time":1317143005,
"fbid":"153538678072594",
"qid":"5657092603540274768",
"s_obj":5,
"s_edge":1,
"s_prnt":28,
"ft_prefix":"feed_story.top_news",
"ft_story_name":"StreamStoryCreateGeneric_ShareStreamContent_External_Other",
"mf_story_key":"10150331666719785",
"object_id":"153538678072594",
"mf_objid":"153538678072594",
"viewstate_id":"3201743663063655712",
"sub_level":"mid",
"sbj_type":"page",
"is_boulder":"1",
"authentic":1,
"pageid":"117307284966434",
"filter":"h",
"pos":14
}'
What do these keys represent? Some of them are straightforward, such as 'sty' as style, 'actrs' is the Facebook-ID of the original poster, and 'pub_time' is the UNIX epoch representation of the post date & time.
In particular, I am interested in understanding what the 'authentic' key represents, as well as the 'fbid' and 'qid' values.
Thanks for your insight, SO.
This is the root of how BFB (Better Facebook user script) can allow filtering, tabbing, etc.
In the HTML source, there is an attribute on each post that looks like this:
data-ft:{
"src":10, "sty":46, "actrs":"14385334364",
"pub_time":1289830690, "fbid":"1485431831867", "s_obj":11, "s_edge":1,
"s_prnt":11, "pos":1, "sec":"new", "filter":"lf",
"app_id":"201278444497"
}
This is the data we need!
BFB parses this when processing each post and extracts the data.
sty = Story type. Each type of story, like wall posts, status updates, pictures, links, etc has a unique story type with its own number. Unfortunately, these are not documented anywhere! I have to figure out the types by observation and trial and error. It's painful. But knowing this type numbers allows BFB to do filtering based on what kind of story it is.
actrs = The unique Facebook id's of the person (or people) that made the post. Again, good for filtering.
pub_time = The time the post was made. This is useful later...
fbid = The unique Facebook ID of the post. Every post has its own ID. At least, it should. See the explanations below for why this is not as reliable as it sounds
app_id = The unique ID of the Facebook application that made this post