FB Graph API: Way to get list of fields for an object through API - facebook

Is there a way how to get the list of fields for a specific facebook object programmatically?
I know there's documentation for that, but I need some introspection - we're building a tool that would enable the user to select from existing fields.
I mean something like: give me a list of fields for user, response: {"id", "name", "first_name", ...}
Or some way how to get all the fields for one object and derive it from that?

Facebook enables you to pass metadata=1 parameter. For example
cocacola?metadata=1
gives you all available connections and fields for the page:
"metadata": {
"connections": {
"admins": "https://graph.facebook.com/cocacola/admins",
"admin_settings": "https://graph.facebook.com/cocacola/admin_settings"
},
"fields": [
{
"name": "id",
"description": "The Page's ID. No access token or user `access_token`. `string`."
},
{
"name": "name",
"description": "The Page's name. No access token or user `access_token`. `string`."
},
{
"name": "link",
"description": "Link to the page on Facebook. No access token or user `access_token`. `string` containing a valid URL."
},
{
"name": "category_lists",
"description": "The Page's categories. No access token or user `access_token`. `string`."
},
{
"name": "is_published",
"description": "Indicates whether the page is published and visible to non-admins. No access token or user `access_token`. `boolean`."
}
Looks like it's official, found it in the getting started manual

Related

Facebook graph api unable to get some properties like admin_notes, labels or custom_labels in comments listing

We are building an app that manage Facebook comments for page admins. When managing the comments, we want to know if there is any "admin_notes" or "custom_labels" that the page admin has previously applied on that specific owner of the comment.
I imagine the API is something like this:
https://graph.facebook.com/v3.3/45013343238491111/comments?order=reverse_chronological&fields=message,from{name,id,custom_labels,admin_notes,likes}&access_token=...
The api above should theoretically return list of comments made on a post, with their owners name, id, and custom_labels etc.
But the comment listing response is like this:
{
"data": [
{
"message": "sdfsdfsdf",
"from": {
"name": "Dora Chan",
"id": "23424292416969420",
"likes": {
"data": [
{
"name": "Page name",
"id": "XXXXXX",
"created_time": "2019-05-29T06:03:42+0000"
}
],
"paging": {
"cursors": {
"before": "Mzg5OTgwNzQ4MjcxNzU3",
"after": "Mzg5OTgwNzQ4MjcxNzU3"
}
}
}
},
"id": "450133432384921_450162525715345"
},
{....
Information like "page likes" is available. But information like admin_notes and custom_labels are not available.
Why is that so?
Note:
I am using page access Token. All page related permissions are granted:
manage_pages, pages_show_list, publish_pages, pages_messaging, public_profile
If I call graph API on that specific user directly, i.e. https://graph.facebook.com/v3.3/[userid]?fields=name,id,likes,custom_labels&access_token=...
The outcome is same, I can see only name, userid, likes, but I cannot see custom_labels

Facebook Graph API - Get user profile from conversations

by using Facebook Graph API I can fetch the conversations between users and my page. One of the returned conversations looks like this:
{
"message": "message content",
"from": {
"name": "My Page's Name",
"email": "198301820627381#facebook.com",
"id": "198301820627381",
},
"to": {
"data": [
{
"name": "John Doe",
"email": "396169264164870#facebook.com",
"id": "396169264164870",
}
]
},
"id": "m_mid.$cAADurJ0X8UhnJ3tfxVg9jYXJW5fp"
}
I see that I got the user's id field. How can I fetch this user's profile (first name, last name, profile pic) base on this field ? (or is there another way ?)
I followed the Graph API's User Reference but all I got are the user's id and name (which I already have from the returned conversation).
profile_pic only works for PSIDs (Messenger bot events), for ASIDs just use the picture field instead

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.

Facebook Graph API does not return full post data

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.

How to visuzlize facebook post

I have a post id (obtained from the Graph API), can I generate a URL which will display this post in Facebook's interface?
Seems there should be something like http://facebook.com/viewpost?postid=6666666666 ...
You want to manually construct a permalink given only the post ID?
The Graph API for a post ID returns the URLs the user should go to to comment on or like the post, assuming the viewing user has permission to do so.
Example:
GET http://graph.facebook.com/19292868552_10150189643478553?access_token={access token here}
Snipped some of the fields of the response, but you're looking for 'actions':
{
"id": "19292868552_10150189643478553",
"from": {
"name": "Facebook Platform",
"category": "Product/service",
"id": "19292868552"
},
// removed fields from response
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/19292868552/posts/10150189643478553"
},
{
"name": "Like",
"link": "https://www.facebook.com/19292868552/posts/10150189643478553"
},
{
"name": "Share",
"link": "http://networkedblogs.com/hGWk3?a=share"
}
],
// Snipped rest of response
In general, the format of a permalink seems to be:
https://www.facebook.com/{source id}/posts/{post object id}
(Source ID being the user or page ID where the post is)
You can't definitely reply on that URL format always being the same; the API response should be always accurate though