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
Related
I have built a Query API for AWS DynamoDB through the AWS API Gateway. Here's a sample response I get after a successful query :
{
"Count":2,
"Items":[
{
"StoreID":{
"S":"STR100"
},
"OrderID":{
"S":"1019"
},
"Date":{
"S":"22nd May"
}
},
{
"StoreID":{
"S":"STR100"
},
"OrderID":{
"S":"1020"
},
"Date":{
"S":"22nd May"
}
}
],
"ScannedCount":2
}
What I want to do is, when the response reaches the API Gateway (before it reaches the user) I want to modify it. I would like to do the following changes to the coming response -
Firstly, remove the ScannedCount value. (keep the Count one)
Then remove all the "S": "<value>" : value should appear directly, like "StoreID": "STR100"
So, the modified response should look like :
{
"Count":2,
"Items":[
{
"StoreID":"STR100",
"OrderID":"1019",
"Date":"22nd May"
},
{
"StoreID":"STR100",
"OrderID":"1020",
"Date":"22nd May"
}
]
}
I hope you understand my problem - Any help is appreciated!
Thanks! :)
Following the blog article Using Amazon API Gateway as a proxy for DynamoDB
Navigate to Integration Response and expand the 200 response code by choosing the arrow on the left. In the 200 response, expand the Mapping Templates section. In Content-Type choose application/json then choose the pencil icon next to Output Passthrough.
And for your example the template should look like this:
#set($inputRoot = $input.path('$'))
{
"Count": "$inputRoot.Count",
"Items": [
#foreach($elem in $inputRoot.Items) {
"StoreID": "$elem.StoreID.S",
"OrderID": "$elem.OrderID.S",
"Date": "$elem.Date.S"
}#if($foreach.hasNext),#end
#end
]
}
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 :)
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
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/",
}
I'm working on a web service API using the HATEOAS REST representation.
My client can create an item (e.g. a stub of a blogpost):
POST /item
204 Created
Content-Type: application/vnd.foo.item+json
{
"id": 42,
"title": "Lorem Ipsum",
"status": "STUB",
"body": "Very long text."
"_links": {
"self": {
"href": "/item/42"
},
"activate": {
"href": "/item/42/activate"
},
}
}
After that the client can activate the item following the activate link (e.g. go live with the post). So it makes another call to the API:
POST /item/42/activate
200 Ok
Content-Type: application/vnd.foo.item+json
{
"id": 42,
"title": "Lorem Ipsum",
"status": "ACTIVE",
"body": "Very long text."
"_links": {
"self": {
"href": "/item/42"
},
"permalink": {
"href": "/item/42/permalink"
}
}
}
Up to here it is fine. But the problem is that I'm looking for a way to tell the client a suggestion about the next action to do (it's backend business logic).
In my case could be:
Bring the user to post page following the permalink
Bring the user to a shop cart to buy post extra features (visibility, more images, homepage positions and so on...)
Tell the user that the post is pending content review
I don't have an idea on how I could encapsulate this information in HATEOAS.
I was thinking to something like:
POST /item/42/activate
200 Ok
Content-Type: application/json
{
"suggested-action": "check-censure-panel",
"censure-reason": "censored (gambling)",
"_embedded": {
"foo.item": {
"id": 42,
"title": "Lorem Ipsum",
"status": "ACTIVE",
"body": "Very long text."
"_links": {
"self": {
"href": "/item/42"
},
"permalink": {
"href": "/item/42/permalink"
}
}
}
}
But the problem is that every suggested action is heterogeneous for extra attributes, another example may be:
"suggested-action": "go-to-checkout",
"product-order": 424242100,
They don't have a common interface, so I can't make a a vnd.foo.suggestedAction+json type.
What is the best way to design this response?
The next action is a state transition, and you seem to be using HAL so any state transitions should be presented as HAL.
Clients of your app need to react to what state transitions your app provides. So one very simple thing you could do is send a Location header to the next resource the app should present. You could even 302 redirect them there instead of 200'ing them with the updated resource.
You could provide the next action as a link...and not necessarily a HAL link. You could do it as a Link header (https://www.rfc-editor.org/rfc/rfc5988) but i think that would be weird, i just bring it up to knock home the point that your app needs to tell your client about a link.
You seem to want to use custom media types, but you could use profile links (https://www.rfc-editor.org/rfc/rfc6906) and mix in a profile into your vnd.foo type. You can stick to your vnd.foo type and just have it defined that there is an optional suggested-action link relationship. The problem in your example is you're defining it with data fields, but use a link:
{
"id": 42,
"title": "Lorem Ipsum",
"status": "ACTIVE",
"body": "Very long text."
"_links": {
"self": {
"href": "/item/42"
},
"permalink": {
"href": "/item/42/permalink"
},
"x:suggested-action" : {
"href" : "/path/to/best/action"
}
}
the client can follow that link, present the user with an option to follow that link, or ignore it. In the middle case, it's nice if your app provides some context to the user, like a title field:
"x:suggested-action" : {
"href" : "http://path/to/check/censure/panel",
"title" : "Check Censure Panel"
}
Also you can give a hint as to the resource the app can expect:
"x:suggested-action" : {
"href" : "http://path/to/check/censure/panel",
"title" : "Check Censure Panel",
"type" : "vnd.censure.panel/json"
}
I personally don't like doing that as i like my client to react to whatever i send them, but it's useful when you give multiple suggested actions:
"x:suggested-action" : [
{
"href" : "http://path/to/check/censure/panel",
"title" : "Check Censure Panel",
"type" : "vnd.censure.panel/json"
},
{
"href" : "http://path/to/checkout",
"title" : "Start Checkout",
"type" : "vnd.checkout/json"
}
]
now the app can decide based on well defined media types which of the suggested actions it wants to do, present, or ignore.