Facebook Graph API 2.12 Insights Data is Blank - facebook-graph-api

GET /2.12/158732947xxxx/insights?metric=page_impressions&date_preset=last_year
returns the following empty data:
{
"data": [
],
"paging": {
"previous": "https://graph.facebook.com/v2.12/158732947xxxx/insights?access_token=xxxxxXzZAzGoN2eAZDZD&pretty=0&metric=page_impressions&date_preset=last_year&since=1451721600&until=1483257600",
"next": "https://graph.facebook.com/v2.12/158732947xx/insights?access_token=xxxxxWfmC7XzZAzGoN2eAZDZD&pretty=0&metric=page_impressions&date_preset=last_year&since=1514793600&until=1546329600"
}
}
I am using the correct Page Token. I am full Admin and Advertiser admin...

As noted by "CBroe" above, the trick is to get a new token for the user first with read_insights checked..Only after that would the Page Token give the result requested

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 :)

FB Graph API: how to get all entities, using pagination

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.

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

How do I get a facebook page access token without iterating the accounts list?

Facebook documents how to get a page access token by having you call the Graph API to get a list of all your fb accounts. This is done by making a GET request to:
https://graph.facebook.com/me/accounts?access_token=USER_ACCESS_TOKEN
However this returns a list of accounts:
{
"data": [
{
"name": "PAGE_TITLE",
"access_token": "PAGE_ACCESS_TOKEN",
"category": "PAGE_CATEGORY",
"id": "PAGE_ID"
},
{
"name": "PAGE_TITLE",
"access_token": "PAGE_ACCESS_TOKEN",
"category": "PAGE_CATEGORY",
"id": "PAGE_ID"
},
...
]
}
I have the fb id of the page I want. Rather than walk the list looking for a matching id, isn't there a Graph API call to directly fetch the block of data? My end goal is to retrieve the page access token.
Do this, just change the PAGE_ID and USER_ACCESS_TOKEN
https://graph.facebook.com/PAGE_ID?fields=access_token&access_token=USER_ACCESS_TOKEN