Facebook Graph API, message field returns null when reading news feed - facebook

My intention is to get the most recent post from the users feed, however the line below does not bring expected results when a wall post is posted on the timeline by a friend, but works well when its posted by the user himself
me/feed?fields=from,id,message&limit=1
All the fields in the above line return values except for the message field. It works fine in my other Facebook account, but it does not work in the other one.
{
"data": [
{
"from": {
"name": "Ted Mad",
"id": "100000145467923"
},
"id": "1841029522785868_1841280962760724"
}
],
"paging": {
"previous": "https://graph.facebook.com/v2.8/1841029522785868/feed?fields=from,id,message&limit=1&format=json&since=1483606096&access_token=EAACEdEose0cBALrWazFWFoRt9VNGZCknu1MDAkUU1jFZBtdPv8rl3F7frMYHtw7Jeslr8uN8XT7un2lXx3U7AtdZCDu8rBz0ZBppxEXYZC3gv61D3Sa8N86SugoPmY0Rg4aJaZCyJQswQVRxiXUBcZAawTHXMsyvp8uGpc0J1HVcExzQ4509OUxzgbWJ2vVyMMZD&__paging_token=enc_AdAqFkXrZAVv9E0mFWSLfmXZCbmAaYl9qCH33z4aZCOxo2xlVYtIcKGIfLDAivHJANP4DkU06kDEPr6TCN8g4kawFjRt3gaxEZApj0sJb7ioEkO3lAZDZD&__previous=1",
"next": "https://graph.facebook.com/v2.8/1841029522785868/feed fields=from,id,message&limit=1&format=json&access_token=EAACEdEose0cBALrWazFWFoRt9VNGZCknu1MDAkUU1jFZBtdPv8rl3F7frMYHtw7Jeslr8uN8XT7un2lXx3U7AtdZCDu8rBz0ZBppxEXYZC3gv61D3Sa8N86SugoPmY0Rg4aJaZCyJQswQVRxiXUBcZAawTHXMsyvp8uGpc0J1HVcExzQ4509OUxzgbWJ2vVyMMZD&until=1483606096&__paging_token=enc_AdAqFkXrZAVv9E0mFWSLfmXZCbmAaYl9qCH33z4aZCOxo2xlVYtIcKGIfLDAivHJANP4DkU06kDEPr6TCN8g4kawFjRt3gaxEZApj0sJb7ioEkO3lAZDZD"
}
}

Related

Facebook webhook, how to get conversation id from mid id

Hello everyone i'm building a chat bot, i'm having a problem that is, when a user sends a message to my app, i don't get the conversation id like "t_31231231231231", instead I get "mid", I don't know how to get the conversation from "mid", i tried to find the document but maybe I haven't found it yet. :(
{
"object": "page",
"entry": [
{
"id": "553014938133297",
"time": 1567149324484,
"messaging": [
{
"sender": {
"id": "2112675102192095"
},
"recipient": {
"id": "553014938133297"
},
"timestamp": 1567149323879,
"message": {
"mid": "n89QDNpjbh7UUZjDj7mkfk-Mqd_vry00MlXChtxjo-ZLokFwJAtZ6udnPZibQjzAZpuqsN64UVjTly5cTCEKTQ",
"text": "dasddsad",
"nlp": {
"entities": {},
"detected_locales": [
{
"locale": "vi_VN",
"confidence": 0.8299
}
]
}
}
}
]
}
]
}
This might not be the ideal solution, but can serve as an improvisation. Since, you have the message_id you can fetch message to determine who the participants are, then you can match them with the participants in the conversations.participants.
What I did was to fetch all the conversations with their participants field.
i.e
curl -i -X GET \
"https://graph.facebook.com/v8.0/me/conversations?fields=participants&access_token=your-access-token-goes-here"
Which returns
{"data"=>
[{"participants"=>
{"data"=>
[{"name"=>"Masroor Hussain",
"email"=>"3275685679217538#facebook.com",
"id"=>"4275685679217538"},
{"name"=>"Testpage",
"email"=>"115083020351552#facebook.com",
"id"=>"115083020351552"}]},
"id"=>"t_781422919067688"}],
"paging"=>
{"cursors"=>
{"before"=>
"QVFIUlRKd1RBYmtvVXlicm95QUNZAbjVKUW5LbU5lYzhQM24ycmY1aTBXM1NTbnRSLURhc2xnSlBnOWE3OTJ4ZAy1KbS1LLVhUUEdqYmM0MmVzZAXZAZAX2xRdzJCbXpJSEowMmxzUHc0NlBXQ0FTVEdRSEZAZASmI2SGxsNlNOdC1XOWNSZADl0",
"after"=>
"QVFIUkdEUjNPek5jbE9RNUhzZAXpJTm9hWERvQVdGYVV5cHlfcDl6cEJyZAG5NaGpjR1NkUHI4R0JDd1VkWEU0RUh2ZADFOQUVzN0RwQ2tyYmpXcThEV0hjUDM2QXAxbFRLWDVzUGoyNmFjbkcyUzl3X0Myc1AtanRYUndjMDBSdVZAJZAnI0"
}
}
}
In the participants.data one participant is the page and the other is page_scoped_user. You can parse the response to match your participants and get the conversation id e.g here the conversation id would be "t_781422919067688"
A little late here but I had the same problem and actually found the solution in the Instagram API documentation. I tried it in the facebook graph api and it worked perfectly.
In the webhook event, you have the message ID and the sender ID. Using the sender ID, you can make a call to the Graph API (yes, still an additional API call) using the following endpoint:
/{page_id}/conversations?access_token={access_token}&user_id={user_id}
this will return only the conversation between your page and the specified user.

Facebook Graph API get comments from Comments Plugin

I'm trying to get all comments from Facebook Comments Plugin running in my application.
Here's a step by step of what i have done
https://graph.facebook.com/{myUrl}
{
"share": {
"comment_count": 43,
"share_count": 1695
},
"og_object": {
"id": {myObjectID},
"description": {myDescription},
"title": {myTitle},
"type": "website",
"updated_time": "2018-05-28T21:50:37+0000"
},
"id": {myUrl}
}
https://graph.facebook.com/{myObjectID}/comments?access_token={pageToken}
{
"data": [ ],
"paging": {
"cursors": {
"before": {beforePointer},
"after": {afterPointer}
},
"next": {nextUrl}
}
}
So despite comment_count = 43, data field is empty.
It's also weird that a {nextUrl} is given although not showing any results.
Haven't found nothing about this in the recent update due to GDPR.
Any ideas?
The graph API has changed recently due to privacy and GDPR concerns.
To get all comments for a page or user first you need to make a call to get all your posts and then make a call for each post to get comments.
Please view the following example end to get all the posts and then post_ids (the call is similar for user posts).
https://graph.facebook.com/v3.2/{pageId}/posts?access_token={accessToken}
post_id looks something like this - 5704324444475_570454233326 and is in the id field of each returned post.
Then call the get comments endpoint from the graph API using the ID(s) returned by the first endpoint.
https://graph.facebook.com/{post_id}/comments?access_token={accessToken}&summary=true
You'll need to make a separate call for each posts to get that post's comments.

Permissions to Read Likes via Graph API

Since the REST API has gone, I need to find another way to read the likes for pages of our webapp.
According to the Graph API docs, the following should return the likes for any object (such as a page):
https://graph.facebook.com/v2.6/{PAGE-ID}/likes?summary=true
Oops, An access token is required to request this resource. Turns out, instead of a real token, you can also build an ad-hoc token witht the app ID and secret:
https://graph.facebook.com/v2.6/{PAGE-ID}/likes?summary=true&access_token={ID}|{SECRET}
The above returns a JSON payload, however, it's empty even though I'm trying this with a page having almost 200 likes:
{
"data": [
],
"summary": {
"total_count": 0,
"can_like": false,
"has_liked": false
}
}
Maybe a permissions problem? The app domain and the page URL domain are identical.
Big thanks for any hints to solve this riddle!
It does work with a simple App Access Token too, but i assume you get the wrong idea about that endpoint. There is no way to get the "Page Fans", you can only get "other Pages the current Page likes" with it. Just try this with your App Access Token:
https://graph.facebook.com/bladauhu/likes?access_token=APPID|APPSECRET
It should return the following JSON:
{
"data": [
{
"name": "FKK Scibes Skulls",
"id": "1391253501090151"
},
{
"name": "Dodgeball Austria",
"id": "387249994631552"
},
{
"name": "Turbojugend Scibes",
"id": "105248832848054"
},
{
"name": "HYDRA! Das endgute Satiremagazin.",
"id": "167084486537"
},
{
"name": "VLÜ Hydra",
"id": "113680962002559"
}
],
"paging": {
"cursors": {
"before": "MTM5MTI1MzUwMTA5MDE1MQZDZD",
"after": "MTEzNjgwOTYyMDAyNTU5"
}
}
}
More information about Tokens:
http://www.devils-heaven.com/facebook-access-tokens/
https://developers.facebook.com/docs/facebook-login/access-tokens/
https://developers.facebook.com/docs/apps/changelog#v2_6_changes:
The likes field on the Page node has been renamed to fan_count
As luschn said in their answer, likes are the other pages liked by that page; if you want to get the number of people that like the page itself, you need to request fan_count.

Facebook Graph API - Getting Data from Subfields

I have been working on a Facebook app for the last couple of weeks. I have successfully posted data to Facebook's Graph API but I have been struggling to get back specific fields. I am using the API explorer to test my various GET attempts. Here's an excerpt of the data that is returned with the api call: me/g_music:listen_to?fields=data
{
"data": [
{
"data": {
"song": {
"id": "355308601243965",
"url": "https://g8-music.herokuapp.com/object/song.php?title=Pierce+The+Veil+-+Bulls+in+the+Bronx&description=Played+On+G8-Music+for+Windows+8.&image=http%3A%2F%2Fuserserve-ak.last.fm%2Fserve%2F174s%2F78366946.jpg",
"type": "g_music:song",
"title": "Pierce The Veil - Bulls in the Bronx"
}
},
"id": "245964195537372"
},
{
"data": {
"song": {
"id": "365613963536278",
"url": "https://g8-music.herokuapp.com/object/song.php?title=Pierce+The+Veil+-+Kings+for+a+Day+%28feat.+Kellin+Quinn%29&description=Played+On+G8-Music+for+Windows+8.&image=http%3A%2F%2Fuserserve-ak.last.fm%2Fserve%2F174s%2F78366946.jpg",
"type": "g_music:song",
"title": "Pierce The Veil - Kings for a Day (feat. Kellin Quinn)"
}
},
"id": "245961632204295"
},
I am attempting to get the value of title but have been unsuccessful so far.
If I try something like: me/g_music:listen_to?fields=data.data... I receive an exception which tells me that "Subfields are not supported by data".
I am relatively new to the graph API so I'm most likely missing something obvious.
You are not missing anything. I verified this through the Graph API Explorer.
Subfields are not supported by data
But you have the whole data, simply fetch the title from the array.

How can I get a facebook users photo comments

Currently when I look at my posts via the GraphAPI:
https://graph.facebook.com/me/posts/
Some posts have their "story" parameter truncated like this (note the ... after the word toe,):
{
"id": "xxxxxxxxx_yyyyyyyyyyyyy",
"from": {
"name": "zzzzzz",
"id": "1234567890"
},
"story": "\"those things pivot at the toe,...\" on XYZ's photo.",
"story_tags": {
"39": [
{
"id": 11111,
"name": "XYZ",
"offset": 39,
"length": 22,
"type": "user"
}
]
}
The above is a comment on a photo within facebook, so the graph api ids=http://.... approach that I have seen elsewhere on SO does not work. When I try to pass in the id to the comment table via FQL I get no data returned. I have all the appropriate permissions in the access token.
Overall what I am trying to achieve is a way to get everything a user has written/typed on facebook recently, so I need:
1.status updates - achieving this via:
select time, message from status where uid=me()
2.check ins - still working on this
3.comments on photos or working on other peoples status - still working on this and the reason for this post