How to get user_id from page scope id - facebook-graph-api

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

Related

Amazon SP-API Listings API putListingsItem How To Update price and quantity? Node.js

I am using amazon-sp-api (JavaScript client for the Amazon Selling Partner API) but this is not limited to this client. All I want to do is use the Amazon SP-API Listings API's putListingsItem call to update the price and quantity of an item I have listed.
productType
According to the ListingsItemPutRequest docs, productType and attributes are required for this call.
Firstly, to obtain the correct productType value, you are supposed to search for a product definitions type using the Product Type Definitions API. So, I do that, and call searchDefinitionsProductTypes, just to discover my product has no matching product type.
Ultimately, I gave the value PRODUCT for productType field. Using PRODUCT, I made the getDefinitionsProductType call and got an object containing an array of propertyNames, shown below:
"propertyNames": [
"skip_offer",
"fulfillment_availability",
"map_policy",
"purchasable_offer",
"condition_type",
"condition_note",
"list_price",
"product_tax_code",
"merchant_release_date",
"merchant_shipping_group",
"max_order_quantity",
"gift_options",
"main_offer_image_locator",
"other_offer_image_locator_1",
"other_offer_image_locator_2",
"other_offer_image_locator_3",
"other_offer_image_locator_4",
"other_offer_image_locator_5"
]
},
On seeing this, I decide list_price and fulfillment_availability must be the price and quantity and then try using these in my code below.
attributes
The attributes value is also required. However, their current docs show no clear example of what to put for these values, which are where I must put price and quantity somewhere.
I found this link about patchListingsItem and tried to implement that below but got an error.
code:
// trying to update quantity... failed.
a.response = await a.sellingPartner.callAPI({
operation:'putListingsItem',
path:{
sellerId: process.env.SELLER_ID,
sku: `XXXXXXXXXXXX`
},
query: {
marketplaceIds: [ `ATVPDKIKX0DER` ]
},
body: {
"productType": `PRODUCT`
"requirements": "LISTING_OFFER_ONLY",
"attributes": {
"fulfillment_availability": {
"fulfillment_channel_code": "AMAZON_NA",
"quantity": 4,
"marketplace_id": "ATVPDKIKX0DER"
}
}
});
console.log( `a.response: `, a.response )
error:
{
"sku": "XXXXXXXXXXXX",
"status": "INVALID",
"submissionId": "34e1XXXXXXXXXXXXXXXXXXXX",
"issues": [
{
"code": "4000001",
"message": "The provided value for 'fulfillment_availability' is invalid.",
"severity": "ERROR",
"attributeName": "fulfillment_availability"
}
]
}
I also tried using list_price :
// list_price attempt... failed.
a.response = await a.sellingPartner.callAPI({
operation:'putListingsItem',
path:{
sellerId: process.env.SELLER_ID,
sku: `XXXXXXXXXXXX`
},
query: {
marketplaceIds: [ `ATVPDKIKX0DER` ]
},
body: {
"productType": `PRODUCT`
"requirements": "LISTING_OFFER_ONLY",
"attributes": {
"list_price": {
"Amount": 90,
"CurrencyCode": "USD"
}
});
console.log( `a.response: `, a.response )
Error (this time seems I got warmer... maybe?):
{
"sku": "XXXXXXXXXXXX",
"status": "INVALID",
"submissionId": "34e1XXXXXXXXXXXXXXXXXXXX",
"issues": [
{
"code": "4000001",
"message": "The provided value for 'list_price' is invalid.",
"severity": "ERROR",
"attributeName": "list_price"
}
]
}
How do you correctly specify the list_price or the quantity so this call will be successful?
Just tryin to update a single item's price and quantity.
The documentation for this side of things is terrible. I've managed to get some of it through a fair bit of trial and error though.
Fulfillment and Availability can be set with this block of JSON
"fulfillment_availability": [{
"fulfillment_channel_code": "DEFAULT",
"quantity": "9999",
"lead_time_to_ship_max_days": "5"
}]
and List price gets set, oddly, with this block. I'm still trying to find out how to set the List Price with Tax however.
"purchasable_offer": [{
"currency": "GBP",
"our_price": [{"schedule": [{"value_with_tax": 285.93}]}],
"marketplace_id": "A1F83G8C2ARO7P"
}]
Hope this helps you out :)

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

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/",
}