Facebook graph: error in after cursor - facebook-graph-api

when I make a get request on facebook graph api, for page search, everything is fine. But when I use the after cursor or click on the 'next' field I get the following error:
{
"error": {
"message": "An unknown error has occurred.",
"type": "OAuthException",
"code": 1,
"fbtrace_id": "B4oyy5hYamh"
}
}
until yesterday everything worked perfectly, but today I found this problem.
this is my first request:
https://graph.facebook.com/v2.10/search?access_token=*******&fields=about,paging&type=place&center=41.817557,12.446137&categories=["FOOD_BEVERAGE"]&distance=2000&limit=25
and this is the request for the next page:
https://graph.facebook.com/v2.10/search?access_token=*******&fields=about,paging&type=place&center=41.817557,12.446137&categories=["FOOD_BEVERAGE"]&distance=2000&limit=25&after=QWJwc3kyZAklVTVpZAMmlEd0hFdXRINWVOU2hPSDQ5SWtYcXFreHFGX2pTVndHMW9DOV9BTmgtVGlxN04xUDJheXRCSGZAabjZAxUVJnbE5wRmcyMU4yQ3J3ZAkRqVVE1NHpjQWhPZAkh5clA1MnUxNV9WTzU1TngzYlhfVkRfZAGs2SWZAkNXNFQ3RQWEd2Rk1hNXdGRW5vdmlNbFh3aDl4YzlSdmxWUkQ4RzFGTnFZAbUxqYzhnMFZASYkxuWHJobUttSkdwZAWZANUnkwN1AyQm93Tnh1bnYwT0ZAEMVRyYXhZAMldFNF9SNjlCMGttWmZA6SGdKSUN4aXZAyLVZAmOUJ4RnM3SFJRNHNUY3lUNDUyOGo2VTdrWUJYcDh3SVd2dDdOWlBzZAUhPZA0tzY0czM25hU25iNmI0ZATN0UFFQZAGlJSFdEd2J3bVUycUZAvNE5YVEw4QlJmTUJmNlpvUWd0Y1pQOE9aWnpKOFlkZAFIxcTU2UXBJTzRR

Your after seems incorrect, it should be a very short code. Have you pasted an access token instead?
This query
https://graph.facebook.com/search?q=food&type=page&limit=3&access_token=ACCESS_TOKEN returns
{
data: [
{
name: "Food Network",
id: "20534666726"
},
{
name: "FOODbible",
id: "996909263665350"
},
{
name: "Food",
id: "113109208703114"
}
],
paging: {
cursors: {
before: "MAZDZD",
after: "MgZDZD"
},
next: "https://graph.facebook.com/v2.5/search?access_token=ACCESSTOKEN&pretty=1&q=food&type=page&limit=3&after=MgZDZD"
}
}
so to fetch the next list, I simply append the after value (MgZDZD) to my initial query to fetch the next page of results. eg
https://graph.facebook.com/search?q=food&type=page&limit=3&access_token=ACCESS_TOKEN&after=MgZDZD

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

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

Where to get product-catalog-id

I am using Facebook marketing API 3.3 version to read product feeds but I don't know where can I get the product-catalog-id.Here is the URL :
GET /v3.3/{product-catalog-id}/product_feeds
You can get your product-catalog-id in the settings page of catalog page (https://www.facebook.com/products/catalogs)
Programatically, I'm using Graph API 13.0, you can fetch your business id via:
GET me/businesses
response:
{ data: [ { id: 12345, ... }, { id: 23456, ... } ] }
Then use the business ID to fetch product catalogs:
GET ${businessId}/owned_product_catalogs
response:
{ data: [ { id: 12345, name: 'foo', ... }, { id: 23456, name: 'bar', ... } ] }
See https://developers.facebook.com/docs/marketing-api/reference/product-catalog

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