How to fetch comments with Facebook Graph API from comments plugin - facebook

I am trying to get all comments from my website.
I have found this method in plugin FAQ:
https://graph.facebook.com/v2.6/?fields=og_object{comments}
&id=<YOUR_URL>
&access_token=<YOUR_TOKEN>
But it neither corresponds to API reference (there's no field named comments in returned OpenGraph object), nor actually works. So I managed only to fetch amount of comments, but not actually their contents. Is it possible to do so?

The code referred to in the FAQ appears to be for v2.6 of the API, and so may be superceded.
I get comments from the Comments Plugin with the following.
First I get the Facebook Graph ID for the URL the Comments Plugin is operating within:
https://graph.facebook.com/v2.8/?id=<<YOUR_URL>>
&access_token=<<YOUR_TOKEN>>
This returns a response like this:
{
"og_object": {
"id": "<<OBJECT_ID>>",
"description": "<<OPENGRAPH_DESCRIPTION>>",
"title": "<<OPENGRAPH_TITLE>>",
"type": "article",
"updated_time": "2017-02-08T13:53:48+0000"
},
"share": {
"comment_count": 0,
"share_count": 0
},
"id": "<<YOUR_URL>>"
}
We then take that Open Graph Object ID and plug it into this:
https://graph.facebook.com/v2.8/<<OBJECT_ID>>/comments?summary=1
&filter=stream
&order=reverse_chronological
&access_token=<<YOUR_TOKEN>>
You'll get an object with a data property which will be an array of comments.
Testing for URL Provided by OP
https://graph.facebook.com/v2.8/
id=http://pdffiller.com/6962253&access_token=[REDACTED]
Returned
{
"og_object": {
"id": "1195506680497732",
"description": "Fill w9 fill out online 2014-2017 form irs instantly, download blank or editable online. Sign, fax and printable from PC, iPad, tablet or mobile. No software. Try Now!",
"title": "2014-2017 Form IRS W-9 Fill Online, Printable, Fillable, Blank - PDFfiller",
"type": "website",
"updated_time": "2017-02-08T12:08:37+0000"
},
"share": {
"comment_count": 0,
"share_count": 24
},
"id": "http://pdffiller.com/6962253"
}
Note the comment_count is zero, hence why no comments are returned by the Graph API

Related

Instagram API response with users not in caption

I want to know what users are tagged in a photo on Instagram, who don't appear in the caption.
Anyone know if this is possible? That is, does the response contain users that are tagged, but that are not physically in the caption text?
https://www.instagram.com/developer/endpoints/tags/
The property you probably want is called users_in_photo. It is an array which contains an array of user objects who've been tagged in the photo. It also contains the geometric coordinates in the photo that the user has been "tagged" at.
Here is an example response using the /media/MEDIA_ID endpoint:
Endpoint Documentation -> https://www.instagram.com/developer/endpoints/media/#get_media
{
"data": {
"users_in_photo": [{
"user": {
"username": "kevin",
"full_name": "Kevin S",
"id": "3",
"profile_picture": "..."
},
"position": {
"x": 0.315,
"y": 0.9111
}
}],
// rest of object...
}
}
I think what you are looking for are username mentions in captions and comments, API does not return this list in API, you will have to search for #usernames in the caption string.
You will have to make a separate API call to get the comments in post (u can only get latest 120), and do a manual string search in each of the comments.
users_in_photo in API response will have an array of users that are actually tagged on photo, not username mentions

Facebook API endpoint to get campaigns of a certain objective?

I'm trying to fetch all of my ad campaigns from Facebook whose objective is "WEBSITE_CLICKS" (ie, driving visitors to your site). When I make a GET request against the following:
/act_myaccountid/adcampaign_groups?fields=objective,name
or, using the official Python Ads SDK:
fields = [facebookads.objects.AdCampaign.Field.objective, facebookads.objects.AdCampaign.Field.name]
campaigns = my_user_account.get_ad_campaigns(fields=fields)
I get something that looks like:
{
"data": [
{
"objective": "NONE",
"name": "name1",
"id": "1234"
},
{
"objective": "NONE",
"name": "name2",
"id": "567"
},
I'd like to be able to only get campaigns with that particular objective. Is there a way to do this? I read through the Ads documentation but didn't see anything.
It's not documented as far I've seen but the FB Ads Manager UI allows such filtering which also happens to work in external Graph API calls.
Make a call to the API with a filtering parameter like so:
filtering=[
{
"field":"<FIELD>",
"operator":"IN",
"value":[
"<VALUE>"
]
}
]
For example, your request would be:
/act_myaccountid/adcampaign_groups?fields=objective,name&filtering=[{"field":"objective","operator":"IN","value":["WEBSITE_CLICKS"]}]

How should we retrieve an individual post now that /[post-id] is deprecated in v2.4?

I just tried through the Graph API Explorer with this path /v2.4/10153513872748291 and I've got this result:
{
"error": {
"message": "(#12) singular links API is deprecated for versions v2.4 and higher",
"type": "OAuthException",
"code": 12
}
}
But https://developers.facebook.com/docs/reference/api/post/ doesn't say anything about deprecation.
I'm not sure if I miss something, or there's another way to get info about an individual post.
Edit: v2.3 works, but v2.4 is the latest one.
Looks like you now need to the combination of the id of the user or page that made the post (or whose wall it is on), an underscore, and then the post id.
For your example post, 10153513872748291, that is made by a page Drama-addict, that has the id 141108613290 – so 141108613290_10153513872748291 will work.
And so does 788239567865981_10153513872748291, because 788239567865981 is the id of the user making the post.
Firstput userId underscore add postId /Likes to check Like status in facebook
userId_post_Id/Likes to fetch Likes Records
userId_post_Id/Comments to fetch Comments Records
https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=303261006522998_751199848395776%2FLikes&version=v2.9
**In this link Right side Get Token indide GetAccessToken to select Permission**
303261006522998_751199848395776/Likes
303261006522998_751199848395776/Comments
{
"data": [
{
"id": "124778301449917",
"name": "Manisha Gera"
},
{
"id": "1680577265523548",
"name": "Rubi Sharma"
}
],
"paging": {
"cursors": {
"before": "MTI0Nzc4MzAxNDQ5OTE3",
"after": "MTY4MDU3NzI2NTUyMzU0OAZDZD"
}
}
}

Getting attachments from Facebook conversations

I currently use the Facebook Graph API to get a inbox conversation. Most of the messages look like this:
{
"id": "1452301718360191_1407164668",
"from": {
"id": "10203840837848742",
"name": "Øyvind Knobloch-Bråthen"
},
"message": "Some message",
"created_time": "2014-08-04T15:04:28+0000"
}
However, some of the messages in the conversation are images, and they are represented like this:
{
"id": "1452301718360191_1407164668",
"from": {
"id": "10203840837848742",
"name": "Øyvind Knobloch-Bråthen"
},
"created_time": "2014-08-04T15:04:28+0000"
}
So basically what is different is that the message is gone. But since there is no mention of the attachment, or url to the image or anything else I can use, I'm not able to display the image in my app.
So my question is: How can I get a hold of the image (or url to the image). Hopefully it will be available in some way when I have the message ID.
With Graph api V2 the egde to retrieve inbox messages is /id/conversations
id is eitheir a user id or a page id
Each conversation message with attachment should return an "attachments" field.
Then for each message with attachment you should query the url https://api.facebook.com/method/messaging.getattachment?mid=message_id&access_tokes=your_access_token
Note that it does not work with graph api v2.1. Unless you curl the query

facebook graph can not get comments

After Search post from graph
https://graph.facebook.com/search?q=watermelon&type=post&fields=from,message,picture,link,name,caption,comments,description,created_time,id&token=XXXXXXXXXXXXX
here will return some data. In the third post:
"from": {
"name": "Alessio Mrbillyplus Frustaci",
"id": "1665626783"
},
"picture": "http://external.ak.fbcdn.net/safe_image.php?d=AQDGoBK_lUeeMb5x&w=130&h=130&url=http\u00253A\u00252F\u00252Fi3.ytimg.com\u00252Fvi\u00252Fjo5GcYeh7XA\u00252Fdefault.jpg",
"link": "http://www.youtube.com/watch?v=jo5GcYeh7XA&feature=share",
"name": "Herbie Hancock \"Watermelon Man\"",
"caption": "www.youtube.com",
"description": "From the 1973 album \"Headhunters\" here's Herbie Hancock with \"Watermelon Man\" Sampled by Super Cat \" Dolly My Baby\" LL Cool J \"1-900-LL Cool J\" Shaquille O'N...",
"created_time": "2011-09-17T17:44:48+0000",
"id": "1665626783_235117223205324",
"comments": {
"data": [
{
"id": "1665626783_235117223205324_3043725",
"from": {
"name": "Alessio Mrbillyplus Frustaci",
"id": "1665626783"
},
"message": "La enne e la doppia effe aaaaaa",
"created_time": "2011-09-17T17:45:52+0000"
}
]
}
},
It is clearly that it has comments in it. So the PostID is 1665626783_235117223205324 and CommentID is 1665626783_235117223205324_3043725? But when I tried search a post or comments, the data return empty.
https://graph.facebook.com/1665626783_235117223205324?access_token=XXXXXXXXXXX//empty
https://graph.facebook.com/1665626783_235117223205324/comments?access_token=XXXXXXXXXXX//empty
https://api.facebook.com/method/fql.query?
callback=json&
query=SELECT%20comments%20FROM%20stream%20WHERE%20post_id%20%3D%20'1665626783_235117223205324'&access_token=XXXXXXXXXXXXXX //empty
What is the big problem?
There may be privacy settings in place which prevent the current user from seeing the posts or comments, where are those comments posted? Are you accessing them with an access_token from a user who can see the content?
As Mahima said, both of those calls should be working and i've tested equivalent calls with posts from my own news feed or page walls.
A call to /1665626783_235117223205324 for me returns false, which indicates i don't have permission to view the item.
This could also be a bug, but you'd need to have a very clear set of sample data to demonstrate the issue so it can be reproduced by Facebook
I tried with post id and comment id both as
http://graph.facebook.com/COMMENT_OR_POST_ID?access_token=APPLICATION_ACCESS_TOKEN
both are working ..
Make sure the access_token you are using is either of the application which you used for posting on a user's wal.. Or the access_token has sufficient read_stream and offline_access permission of the user ..