FB Graph API: how to get all entities, using pagination - facebook-graph-api

I'm trying to get all posts I'm liked on Facebook, using Graph API (without SDK). I'm able to get first page of data, and can't understand how to fetch next data page using cursors.
My request looks like:
GET /v3.2/me/likes?limit=100
And response is something like this :
{
"data": [
{
"name": "<name>",
"id": "<id>",
"created_time": "2018-12-08T08:48:47+0000"
},
...
...
],
"paging": {
"cursors": {
"before": "MTQ5MTkzOTE2NDQ2OTQyNAZDZD",
"after": "Mjk5NzQzMTYzNTI1Mjc3"
}
}
}
Adding "after" parameter to request, causes empty response:
GET /v3.2/me/likes?limit=100&after=Mjk5NzQzMTYzNTI1Mjc3
Will be glad for help.

Related

Facebook Graph API does not return shares but comment count and like count are ok

I am trying to get shares, comments and likes count from Facebook graph API. Everything works great except the shares did not return in the response payload.
Here is the params I sent:
mypost_id?fields=message,shares,likes.summary(true).limit(0),comments.summary(true).limit(0)
Here is the response
{
"message": "HUAWEI WiFi Router AX3",
"likes": {
"data": [
],
"summary": {
"total_count": 2,
"can_like": true,
"has_liked": true
}
},
"comments": {
"data": [
],
"summary": {
"order": "ranked",
"total_count": 2,
"can_comment": true
}
},
"id": "103851678893717_115163661095852"
}
Here is the graph API screenshot
I've noticed that the shares parameter was marked as grey ( see in the figure above ), there might be something wrong with it.
I am using Facebook graph v13.0.
Is there anyone experiencing this issue before?
Looks like the API only returns shares, if there are any actual shares.
For posts with no shares, this is simply completely omitted from the result.
For posts that do have shares, you should get "shares": { "count": xy } in the resulting structure.

How to get campaign ID from a real time facebook lead?

I'm using Facebooks Webhooks for lead generations. I successfully can fetch leadgen_id from the Facebooks callback.
So this is what Facebook returns for the leadgen field:
{
"object": "page",
"entry": [
{
"id": "0",
"time": 1583178814,
"changes": [
{
"field": "leadgen",
"value": {
"ad_id": "444444444",
"form_id": "444444444444",
"leadgen_id": "444444444444",
"created_time": 1583178812,
"page_id": "444444444444",
"adgroup_id": "44444444444"
}
}
]
}
]
}
Is it possible to somehow get campaign ID from these values?
I figure out how to get the campaign id from leadgenId. we can use the Facebook graph leadgen GET API
GET /v6.0/<leadgenid>?access_token=<ACCESS_TOKEN>&fields=campaign_id'
Host: graph.facebook.com
Hope it'll help someone in the future :)

Facebook Messenger Webhook get "outbound" message text

I am getting the following back as a webhook (Message-Delivered Callback) but I need to get the actual content of the message that was delivered. The Message-Received Callback has a "text" field that contains this information, but this one does not.
{
"object": "page",
"entry": [{
"id": 2880130XXXX7538,
"time": 1462299418787,
"messaging": [{
"sender": {
"id": 1261XXXX3865793
},
"recipient": {
"id": 2880XXXX7977538
},
"delivery": {
"mids": ["mid.146XXXX412750:6bd62757XXXXd68848"],
"watermark": 1462XXXX12769,
"seq": 50
}
}]
}]
}
I have tried unsuccessfully to use graph api with the message id but the docs are a little unclear if this is possible (https://developers.facebook.com/docs/graph-api/reference/v2.6/message/)
The token I am using has the following permissions: read_page_mailboxes, manage_pages, pages_messaging.
Any help would be greatly appreciated!!
Add "m_" to your delivery mids, so in this case:
m_mid.146XXXX412750:6bd62757XXXXd68848
And then make a facebook-graph-api request using that as the "message-id" in the URL. Use fields=message to get the message text.
Reference:
https://developers.facebook.com/docs/graph-api/reference/v2.6/message/
You can try this code:
$M = $input['entry'][0]['messaging'][0]['message']['text'];
AND "$M" is what you want.
it's work! But i can't explain why

Recommended pattern to implement global Search with multiple Objects type (Ember 2 + JSONAPI)

I am new to Ember and I will like to implement a server side search endpoint that returns results for several models/tables in DB.
Trying to figure out what is the best practice to do this in Ember.
Server results can contain several types of objects/models, each model is already defined in ember-data.
So far I am able to retrieve the results (I can see the results in ember-inspector) but I am not able to render it properly (I only have access to first object for some reason).
Current architecture:
rails-5 server with JSONAPI response
ember 2.3 with multiple models
Flow:
POST /search with body:
{"search":{"query": "xxx","size": "10"}}
RESULT:
{
"data": [
{
"id": "111111",
"type": "foo",
"attributes": {
"x": "y"
}
},
{
"id": "222222",
"type": "bar",
"attributes": {
"z": "y"
}
}
]
}

How is a json paginated resource supposed to look like?

With Ember Data and Jsonapi. How is a json paginated resource supposed to look like?
I built my response so it looks like:
"meta": {
"page": {
"number": 1,
"size": 5,
"total": 39
}
},
"links": {
"self": "http://localhost:3099/api/v1/articles",
"prev": null,
"next": "http://localhost:3099/api/v1/articles?page[number]=2",
"first": "http://localhost:3099/api/v1/articles?page[number]=1",
"last": "http://localhost:3099/api/v1/articles?page[number]=39"
},
"data": [
...
]
But I am not exactly sure if this is the right format. based on the explanation at http://jsonapi.org/format/#fetching-pagination
Or, are the pagination links (i.e. prev, next, first and last) supposed to be in meta.page ?
You could use ember-cli-pagination and its format to do pagination. I'm pretty sure Ember Data does not follow the JSON API spec strictly.
Based on your sample this could be a format:
{
"meta": {
"total_pages": 3,
"page": 1
},
"articles": [
{"id": 1, "title": "Hello World", "body": "More to Come"},
// ......
]
}
The request URL of this payload could be http://localhost:3099/api/v1/articles?page=1. See the API for more info.
Ember Data doesn't follow the JSON spec strictly so you should concentrate more on setting up the JSON with what ED needs. I would personally move the 'links' info into the meta tag. Otherwise Ember-Data will attempt to put them into a model called 'links', which may not be what you want. If you do intend to store those inside a separate 'links' model, then what you have is fine.