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

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

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.

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.

How to get user_id from page scope id

I'm trying to get page scope id (PSID) from user_id
As I know, one user have two kind ID: one for Graph API Platform (GID) and one for Messenger platform (MID).
(PSID = MID, user_id = GID)
I've found out the way to change from GID to MID:
GET /{GID}/ids_for_pages?access_token=[page_access_token]&appsecret_proof=[appsecret_proof]
enter code here
json I receive:
{ "data": [
{
"id": "MID here",
"page": {
"name": "Trang web b\u00e1n h\u00e0ng",
"id": "1863210517250420"
}
} ], "paging": {
"cursors": {
"before": "MTg2MzIxMDUxNzI1MDQyMAZDZD",
"after": "MTg2MzIxMDUxNzI1MDQyMAZDZD"
} }}
Now I want to change from MID to GID.
I try this
GET /{MID}/ids_for_pages?access_token=[page_access_token]&appsecret_proof=[appsecret_proof]
But I get error
{ "error": {
"message": "(#230) Requires pages_messaging permission to manage the object",
"type": "OAuthException",
"code": 230,
"fbtrace_id": "D+x01MWia1s" }}
I've read Facebook's document in here but I can't find out the way to change from MID to GID.
Please help me. Thanks for reading my problem.
You can try with ids_for_apps end point as being described here

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 to get count of shares on Facebook for given Instagram Photo through API?

as everyone know, there is possibility to share photos on Instagram to Facebook. What I would like to ask you is if there is API way how to get number of such shares?
Any idea?
Thx for your tips in advance!
Jakub
You could use the /?id (respectively URL) endpoint:
https://developers.facebook.com/docs/graph-api/reference/v2.5/url
meaning a request would look like
GET /?id=https://instagram.com/p/9q0-tUuSyL/
which returns
{
"og_object": {
"id": "960618280676059",
"type": "website",
"updated_time": "2015-11-04T16:14:14+0000",
"url": "https://instagram.com/p/9q0-tUuSyL/"
},
"share": {
"comment_count": 0,
"share_count": 13
},
"id": "https://instagram.com/p/9q0-tUuSyL/",
}