Facebook Graph API - Get user profile from conversations - facebook

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

Related

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 get gender of users attending some event (Facebook Graph API)?

Is there a way to get gender of facebook users via Facebook Graph API, that are attending some event? Or just by users' ids?
You can consume the events/attending endpoint:
https://developers.facebook.com/docs/graph-api/reference/v2.2/event/attending
Your request would be /{TheEventId}/attending
Which returns a list of user objects:
https://developers.facebook.com/docs/graph-api/reference/v2.2/user
...which looks like this:
{
"data": [
{
"name": "What What",
"rsvp_status": "attending",
"id": "10152412233197215"
},
{
"name": "What What",
"rsvp_status": "attending",
"id": "1682602711966379"
},
{
"name": "What What",
"rsvp_status": "attending",
"id": "10201675684423330"
}
]
You would then need to use the user id to query for each user's details. The user object has a gender field.
{
"id": "10142215948176947",
"gender": "male",
...
}
Also note the permission limitations:
gender & locale can only be accessed if:
The person queried is the person using the app.
The person queried is using the app, and is a friend of the person using the app.
The person queried is using the app, is not a friend of the person using the app, but the app includes either an app access token or
an appsecret_proof argument with the call

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

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

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