Custom Internal Facebook App Graph API not returning Page's Post Comments - facebook

I am trying to create a Facebook app that can pull down the comments on the posts of a business page I have created. I have successfully created the app and connected my Facebook page through OAuth. However, none of the comments on the page's posts are coming through. Any help would be appreciated, please see below code.
https://graph.facebook.com/v3.2/{pageId}/?access_token={accessToken}&fields=id,name,posts
Response:
{
"id": "{pageId}",
"name": "Page Name",
"posts": {
"data": [
{
"created_time": "2016-01-15T19:46:28+0000",
"message": "POST 1",
"id": "47829695884833182_111061999222282539"
},
{
"created_time": "2016-01-15T19:45:56+0000",
"message": "POST 2",
"id": "4734458296958848182_111061922795615892"
}
}
}
The same thing happens if I use the following endpoint:
https://graph.facebook.com/v3.2/{pageId}/feed?access_token={accessToken}
Or
https://graph.facebook.com/v3.2/{pageId}/posts?access_token={accessToken}
I found a reference showing I may be able to get comments through this endpoint:
https://graph.facebook.com/v3.2/{pageId}/comments?access_token={accessToken}
However I get the following response:
{
"error": {
"message": "(#100) Tried accessing nonexisting field (comments) on node type (Page)",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "EN938TNAHM6"
}
}

With all but the last request you are not asking for comments anywhere. And with the last one you are trying to ask for comments on the page object itself, which are not a thing.
You need to ask for the comments, on either the feed or posts endpoint:
/{pageId}/feed?fields=comments
/{pageId}/posts?fields=comments
And if you want to get other info about the page as well in the same request, you can use Field Expansion syntax,
/{pageId}?fields=id,name,posts{comments}
(Any other fields of the posts you might want besides the default id, you’d need to list there comma separated - posts{message,comments,...})

I was able to get comments by using the following request:
https://graph.facebook.com/{post_id}/comments?access_token={accessToken}&summary=true
post_id looks something like this - 57042555475_57045425233226
You have to get comments by posts not pages so first you need to make a call to get all your posts and then make a call for each post to get comments.

Related

Get All Posts from Facebook Page

I am looking for the information posted on the facebook page. I am able to hit the api as below https://graph.facebook.com/v2.8/203511053776284/feed?limit=100&access_token=XXXXXXXXXXX&format=json. I am able to get the below data but no images related with post.
data": [
{
"message": "This is my first post",
"created_time": "2018-05-16T08:05:02+0000",
"id": "203511053776284_203511440442912"
}
]
Any way to get all the information from facebook page.
You need to pass fields value to fetch additional data.
https://graph.facebook.com/v2.8/203511053776284/feed?fields=id,name,message,story,created_time,link,description,caption,attachments{media,type,subattachments}&limit=100&access_token=XXXXXXXXXXX&format=json.
I recommend exploring Graph API Explorer tool.

Get scraped data from facebook graph api using url reliably

My app needs to get data facebook scrapes from URLs. Up until now we were getting it using
POST /?id={object-instance-id or object-url}&scrape=true
Which is detailed in updating object section in https://developers.facebook.com/docs/sharing/opengraph/using-objects
For example
POST /?id=http://google.com
{
"url": "http://www.google.com/",
"type": "website",
"title": "Google",
"image": [
{
"url": "http://www.google.com/images/branding/googleg/1x/googleg_standard_color_128dp.png"
}
],
"description": "Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.",
"updated_time": "2015-10-06T11:34:58+0000",
"id": "381702034999"
}
Notice image section.
Unfortunately if og tags are configured wrongly on the server
POST /?id=http://some.page.with.bad.tags.com
{
"error": {
"message": "Invalid parameter",
"type": "FacebookApiException",
"code": 100,
"error_subcode": 1611016,
"is_transient": false,
"error_user_title": "Object Invalid Value",
"error_user_msg": "Object at URL 'http://some.page.with.bad.tags' of type '' is invalid because the given value '/some-bad-value' for property 'og:url' could not be parsed as type 'url'.",
"fbtrace_id": "abcabcabc"
}
}
Which returns nothing interesting.
Attempt to GET the url returns this:
{
"og_object": {
"id": "381702034999",
"description": "Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.",
"title": "Google",
"type": "website",
"updated_time": "2015-10-06T11:40:04+0000",
"url": "http://www.google.com/"
},
"share": {
"comment_count": 2,
"share_count": 13494003
},
"id": "http://www.google.com"
}
Which misses image section. I cannot find in the documentation any way to retrieve result with images without using POST /?id={url}, but that fails on any errors in og tags.
GET /{ObjectId}
returns only type and created_time
Entering the same broken link in https://developers.facebook.com/tools/debug/ results in page which contains image, description, title and captions for the page. Which I need. So it means facebook stores them, even though page has wrong tags, but I need a way to fetch them. Unfortunatelly I cannot provide link for broken url due to NDA, and I couldn't find other page with broken tags.
If the page contains invalid Open Graph markup this seems expected, also do not confuse the Graph API with some sort of datasource or a scraping service you can utilize to generate the preview for web content.
If Facebook , for whatever reason, can't parse the Open Graph tags of a URL it will try to make a good guess based on the content of the page (large junks of text, images it finds, title tags etc.) to build the preview so you might get some sort of data back from GET /{object-id} which can just be a guess instead of actual og:.. data.
In case you really need a more or less failsafe solution, you could build your own scraper that looks for Open Graph tags.

Can't get Facebook user id by Graph

I'm working on an iOS app and noticed that one user is not loaded when I do a requestForMyFriends.
After looking more into this it seems that the Graph API explorer also doesn't return anything for the particular Facebook user. It's a user and not a Fanpage or something.
So:
I've the page for example (which when I enter In my browser will bring up the Page nicely): https://www.facebook.com/user-name
https://graph.facebook.com/https://www.facebook.com/user-name
Will return:
{
id: "https://www.facebook.com/user-name"
}
https://graph.facebook.com/user-name
Will return:
{
error: {
message: "Unsupported get request.",
type: "GraphMethodException",
code: 100
}
}
http://findmyfacebookid.com/ wil return nothing.
The graph API will return:
{
"error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100
}
}
I'm trying to reproduce this with my test Facebook account and put all restrictions to the max but I always get a nice result with a FacebookId.
My question:
What settings do I need to change to my test Facebook account to reproduce this problem?
"Unsupported GET Request" covers many situations, but at the root the message means you tried to request something via the API which is not available to you via the API
For a request which attempts to retrieve data about a known username or user ID the most likely reasons are:
User has blocked your app
User has disabled all platform apps in their privacy settings
User has deactivated their account
User has deleted their account
if i had to bet, I'd say it's the second one in this case
The problem is the parameter, you don't have to pass in the whole URL of a profile, just the username/profile-id.
For example: we want to get the info of Mark Zuckerberg. His Facebook username is zuck. The URL would be https://graph.facebook.com/zuck and will return the following output
{
"id": "4",
"name": "Mark Zuckerberg",
"first_name": "Mark",
"last_name": "Zuckerberg",
"link": "http://www.facebook.com/zuck",
"username": "zuck",
"gender": "male",
"locale": "en_US"
}
Using https://graph.facebook.com/4 (4 is the profile id of Mark Zuckerberg) would produce the same output.
Edit
After some further investigation it turned out that said user might have deactivated her account and that is why you see this error. I have used a testuser of one of my apps, went to Settings -> Security -> Deactivate my account and taxa, every request to the Graph API returned the result you're seeing.

How to get who and when a user shared a Facebook post

For my Facebook posts my friends share (not likes) I would like get who shared it and when. Using the graph api I can get the like or comment information and the number of times a post has been shared.
What I am looking for is a graph api call or Facebook fql query for shares which returns a result set similar to this:
data": [
{
"id": "user_id_1",
"name": "Username 1",
"created": "some date"
},
{
"id": "user_id_2",
"name": "Username 2",
"created": "some other date"
}
]
I am also looking for the exact thing for long time now. Since Facebook shows the list of users who shared the post, I was expecting that the same will be available in Graph API. But unfortunately nothing such exists till date.
The best workaround I could find for this problem is scraping the Facebook page for the list of users who shared the given post. I haven't yet tried this solution but this should solve the problem for now. The only issue here is, if Facebook changes the HTML structure of that page, the scraper will have to modified.

Remove facebook like using graph api

Using GET https://graph.facebook.com/288095787880494/likes/159222380758097 returns me
{
"data": [
{
"name": "Vote For Prophet Hazrat Muhmmad (PBUH) the best man of world",
"category": "Cause",
"id": "159222380758097"
}
],
"paging": {
"next": "https://graph.facebook.com/288095787880494/likes/159222380758097?format=json&limit=5000&offset=5000&__after_id=159222380758097"
}
}
Now i want to remove this like. How do I do that? When I use HTTP Delete I get the following error:
{
"error": {
"message": "(#3) App must be on whitelist",
"type": "OAuthException"
}
}
You are not allowed to remove likes for Facebook Pages. Only for post, comment and URL's owned by your application.
To be able to do this your application must be whitelisted by Facebook which can only be done by contacting Facebook directly (and will probably require some kind of agreement and cost you money as well...)
Sounds like maybe two issues. Maybe the same. But try what I suggest in #2. Maybe facebook is spitting out a false/misleading error message.
Your app and or page is currently on the facebook naughty list. "Error code: (#3) App must be on whitelist"
You need to use a PAGE access token and not a USER access token. "It says I need to switch back to my Username in order to do that though as I mentioned earlier this link has been liked by the Page"