Facebook Graph API does not return full post data - facebook

I'm using the Facebook Graph API to fetch a public page feed. I created a basic application to get appId and secret. When I make a call to PUBLIC_PAGE_ID/feed I can retrieve the correct list of posts in JSON, but they are missing all the field I need, described in docs, and only have message, created_time and id:
{
"data": [
{
"message": "...",
"created_time": "2015-06-11T07:57:05+0000",
"id": "23X12XXXXXX9836_11XXXXXXXX610XXXX52"
},
...
Why all other data isn't there?

The response to your query: /id/feed is the default response. To access more data, you have to pass a fields parameter with the keyword of data you would like to retrieve.
For example: <id>/feed?fields=id,message,picture,shares
This will return:
{
"data": [
{
"id": "1234567890",
"message": "Message",
"picture": "http://fbcdn.com/xxxxxx.jpg",
"shares": {
"count": 0
}
}
}

What I could figure out is you should submit the app for review with at least one permission what your app still needs and then you will get back every data what you ask in the fields parameter.

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.

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.

Is it possible to get user detailed using facebook API V2.6

I am using the "taggable_friends" api to get the list of all friends then uses the user ID (a string of 110 chars) to get user detailes like this:
FB.api('/' + gFriend.id , 'GET',{},
function(response) {
console.log("response",response)
});
In the result I get an error
(#803) Some of the aliases you requested do not exist: {The user Id I have submitted}
Did FB blocked user details API in version 2?
taggable_friends if for tagging only, you can´t use it for anything else and you don´t get a User ID. You only get a "tagging token" that can only be used for tagging. If you just want to create a "friend pic collage", you need to use /me/friends instead. Of course you will only get friends who authorized your app with the user_friends permission.
[from comments] I want to show friend pic collage
The taggable_friends endpoint does return URLs of the friend’s profile pictures already.
You get a data structure like this,
{
"data": [
{
"id": "AaKYNqeDaP…",
"name": "Foo Barski",
"picture": {
"data": {
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/v/t1.0-1/p50x50/…"
}
}
},
{
"id": "AaKBGEbAAvYU…",
"name": "Some One Else",
"picture": {
"data": {
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/v/t1.0-1/p50x50/…"
}
}
},
So all you need to do is use those URLs provided in the picture structure.

How to get the user data of a facebook group post? The original poster

I have gotten a post object from the Facebook Graph API as such:
GET/v2.5/142679255268_10153887281355269
Which returns an object like so:
{
"created_time": "2016-03-25T03:28:50+0000",
"message": "Whats up everybody, I am here now",
"id": "142679255268_10153887281355269"
}
How can I get the profile of the user who posted this?
I have looked through the documentation and couldnt find anything, but I know its possible.
This would work for the Post item:
/142679255268_10153887281355269?fields=from
It returns the following JSON:
{
"from": {
"name": "Bhumi Patel",
"id": "10153245821277822"
},
"id": "142679255268_10153887281355269"
}
More information: https://developers.facebook.com/docs/graph-api/reference/v2.5/post/
Edit: For data privacy reasons, you may not get the name of the user anymore.

how to get facebook post after a graph search?

https://graph.facebook.com/search?access_token=xxxxxx&q=hello&type=post&fields=from,message,picture,link,name,caption,description,created_time&limit=1&locale=en_US&scope=publish_stream,offline_access,user_status,read_stream
After such a graph search, I get some data like:
{
"data": [
{
"from": {
"name": "Eric Fluegge",
"id": "100000626293694"
},
"message": "Well, here's go nothing. Hello Tennessee.",
"created_time": "2013-03-30T19:23:44+0000",
"id": "100000626293694_567340783296793"
}
],
"paging": {
"previous": "https://graph.facebook.com/search?fields=from,message,picture,link,name,caption,description,created_time&q=hello&limit=1&type=post&locale=en_US&access_token=XXXXXXXXXXXXX&since=1364671424&__previous=1",
"next": "https://graph.facebook.com/search?fields=from,message,picture,link,name,caption,description,created_time&q=hello&limit=1&type=post&locale=en_US&access_token=XXXXXXXXXXXXX&until=1364671423"
}
}
so, is "id": "100000626293694_567340783296793" a post id? If so, how to use this post id, query again, get only this certain post information? I would like to store post id to mysql table, then I want to query the post anytime in the future, thanks.
EIDT: in app setting, i have set the publish_stream,offline_access,user_status,read_stream
EIDT2:
I have tried into Graph API Explorer, choose read_stream and generate a long live token.
SELECT post_id, actor_id, message, type, attachment FROM stream WHERE post_id = "100000626293694_567340783296793"
the result still empty. so I cannot get a post bcause i am not a friend of the post auther? or 100000626293694_567340783296793 is not a post id? or other reason?
Yep, the "id": "100000626293694_567340783296793" is a post ID, you can query its data again with the following URL: http://graph.facebook.com/100000626293694_567340783296793
Attention!
You should ask for the read_stream permission/scope too! Or else you'll get the following error:
{
"error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100
}
}
And of course, append the access_token to your GET url. (and don't forget https too)
You can check the Graph API Reference here: Post - Facebook Developer Reference