Facebook Marketing API returns error on "breakdowns call" - facebook

I'm trying to make an API call with the folowing URL
act_XXXXXXXX/insights?fields=ad_id,clicks,unique_clicks,impressions,reach,spend,date_start,date_stop,actions,action_values,unique_actions,account_id&level=ad&breakdowns=platform_position&time_range={"since":"2019-09-07","until":"2019-09-07"}
and the response is :
{
"error": {
"message": "(#100) Current combination of data breakdown columns (action_type, platform_position) is invalid ",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "XXXXXXXXXXXXXXXXXXXX"
}
}
the reason is in "breakdown" value = "platform_position"
but the problem is that I need exactly that breakdown :(
when I do an API call and change "breakdown" in URL to something else, for example to "publisher_platform":
act_XXXXXXX/insights?fields=ad_id,clicks,unique_clicks,impressions,reach,spend,date_start,date_stop,actions,action_values,unique_actions,account_id&level=ad&breakdowns=publisher_platform&time_range={"since":"2019-09-07","until":"2019-09-07"}
it is OK and responds with data.
I don't know why it happens because I'm not specifying any "action_type" breakdown but it tells that I am :(
What I've tried:
I tried to remove all the parameters from that URL one by one but it still returns an error
The main questions are: why the API call for "breakdown" value = "platform_position" fails and how to make it work.
Thanks.
PS: you can use FB API testing tool to test requests to FB api.
I'm using API version v8.0

You will need both publisher and position:
breakdowns=publisher_platform,platform_position

Related

What is the expected request to get GoToWebinar webinar details based on organiser_key?

I am trying to fetch GoToWebinar details via the
Get Webinars method
​/organizers​/{organizerKey}​/webinars
listed on the GoToWebinar API reference.
I'm passing the below body:
{
"fromTime":"2015-07-13T10:00:00Z",
"toTime":"2015-07-13T22:00:00Z"
}
But in response, I get the below error:
{
"errorId": "26a9b9a8-3a92-45b0-acdd-7ac3c3f485ac",
"requestId": null,
"timeStamp": 1587960550357,
"reason": "invalid.data",
"errorCode": "invalid.data",
**"description": "Required DateTime parameter 'fromTime' is not present",**
"incident": "5801952841989547523",
"details": null
}
The API reference guide does not specify any request structure, just mentions what is needed to be sent, and I have built my logic on the same. Yet I am unable to get a proper response.
Can anybody help me in understanding what the expected request should be?
Since this is a GET HTTP call you can not add these parameters to the Body. I mean you can but it won't be sent along with the call (only with POST/PUT). So you should add the two fields you provided to the Query Parameters instead.

Facebook's Batch Request not picking up a JSON parameter

My goal is to create a number of ads using Facebook's Batch API : https://developers.facebook.com/docs/marketing-api/asyncrequests/v2.9
I am sending a POST request at this URL:
https://graph.facebook.com/v2.9/act_158365238/ads
I am sending 2 parameters as per the documentation:
1- access_token
2- batch
The JSON in the batch parameter looks like :
{
"method": "POST",
"relative_url": "v2.9\/act_158365238\/ads",
"attached_files": "test1",
"body": "creative={\"title\":\"Test title 1\",\"body\":\"Test body 1\",\"object_url\":\"https:\/\/apps.facebook.com\/testapp\/\", \"image_file\":\"test1.jpg\"}&targeting={\"countries\":[\"US\"]}&name=test1"
}
The Problem
When I send this request with POSTman or my PHP code, it throws the following error
{
"error": {
"message": "(#100) The parameter creative is required",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "Gj2sG7N8l1f"
}
}
However when I send the exact same request via Facebook's Graph API tool, it successfully creates the ads.
According to the API Documentation provided to create creatives you should be posting to the URL "v2.9/act_187687683/adcreatives"... The fragment of the batch that you are showing is used to create an Ad.
If, as you say, your intention is to create an AdCreative then you should be using something like the above, which differs in the body from what you are using:
{
"method": "POST",
"name": "create_creative",
"relative_url": "v2.9/act_187687683/adcreatives",
"attached_files": "test1",
"body": "title=Test title&body=Test body&link_url=http://www.test12345.com&image_file=test1.jpg"
}
In the other hand, if what you are creating is an add, then you should consider referencing the AdCreative by its ID as is done in the examples, hence in the case of a creative added in the same batch you could use the relative reference to the name:
creative={\"creative_id\":\"{result=create_creative:$.id}\"}
or if it is a creative already created you can reference it by the creative_id:
creative={\"creative_id\":\"123456\"}
I think the message is a red herring -- it's not seeing your body's creative field because the OAuth isn't properly set in your POSTman requests, so it isn't parsing the body or seeing the creative field.
If you don't know how to set OAuth in POSTman, here's a good tutorial:
https://docs.brightcove.com/en/video-cloud/concepts/postman/postman.html

"message": "Unsupported post request. Object with ID does not exist, cannot be loaded due to missing permissions

I have two apps on facebook. In one, I can make API calls. In the other, I can not.
I checked the configuration and the settings are the same.
Can you help me?
Example: https://graph.facebook.com/860599774051206/?access_token=APP_ID|APP_SECRET
https://graph.facebook.com/860599774051206/notifications?template=#[860599774051206]test&access_token=APP_ID|APP_SECRET&method=post
the error is:
{ "error": { "message": "Unsupported post request. Object with ID
'860599774051206' does not exist, cannot be loaded due to missing
permissions, or does not support this operation. Please read the Graph
API documentation at developers.facebook.com/docs/graph-api",
"type": "GraphMethodException", "code": 100, "fbtrace_id":
"BRW7BqFeEER" } }
RESOLVED:
Any app can change the user_id
In an app the user_id is 962084030569446, in the other 860599774051206
Thakns for all.
I faced this issue when I was trying to post a response to an user from a page. I used the graph API me/accounts and got the list of pages. From there I retrieved the access_token of the page from which I'm going to post the response. I got the same error mentioned in the question.
The issue for me is the user account to which I was supposed to respond is locked due to security. This is the error I got from facebook when I tried to login
You can't use Facebook at the moment
This is the error I got for the post api call
{
"error": {
"message": "Unsupported post request. Object with ID 'xxx' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"error_subcode": 33,
"fbtrace_id": "yyy"
}
}
Once the account security is resolved, the issue is resolved.
While unrelated to the OP problem I thought I would contribute, I got this error when posting to the Offline Events endpoint https://graph.facebook.com/v2.8/<business_id>/events. I had posted from a node.js app successfully, then when porting the approach to a .Net implementation in our Linnworks order management system, got this error.
Turned out, I had mis-typed the access_token parameter that goes in the form data, i.e.
System.Collections.Specialized.NameValueCollection formFields = new System.Collections.Specialized.NameValueCollection();
formFields.Add("accessToken", accessToken);
formFields.Add("upload_tag", "store_data");
formFields.Add("data", data);
Should have been:
System.Collections.Specialized.NameValueCollection formFields = new System.Collections.Specialized.NameValueCollection();
formFields.Add("access_token", accessToken);
formFields.Add("upload_tag", "store_data");
formFields.Add("data", data);
Getting the access_token field wrong in this way caused this 'Object with ID does not exist' which is a bit of a red herring. I guess that, once the access_token value was not provided, no objects could be enumerated in our account because the request didn't authenticate in order to provide permissions, and so the object was 'not found'
(you do not have to use NameValueCollection, this is just a by-product of me using the multipart post implementation suggested here Upload files with HTTPWebrequest (multipart/form-data))
In my case - I had to use the app-id to get the list of pages using me/accounts.
Once I identify the page that I want to post the message to, I have to use the page-id to feed page-id/feed.
This solved the issue.
For example:
$response = $fb->get('/me/accounts', (string)$selBehRow1["fb_app_access_token"]);
foreach ($response->getDecodedBody() as $allPages)
{
foreach ($allPages as $page )
{
if (isset($page['id']) && $page['id'] == $selBehRow1['fb_page_id'])
{ // Suppose you save it as this variable
$appAccessToken = (string) $page['access_token'];
break;
}
}
}
$response = $fb->post(
//this is wrong: '/'.$selBehRow1["fb_app_id"].'/feed',
'/'.$selBehRow1["fb_page_id"].'/feed',
array(
"message" => "$msg",
"link" => "$link",
//"picture" => "http://www.example.net/images/example.png",
"name" => "$name",
"caption" => "$caption",
"description" => "$description"
),
$appAccessToken
);
}
i think post_id is wrong you can check it once
https://graph.facebook.com/860599774051206_4548643168486465/?access_token=APP_ID|APP_SECRET
https://developers.facebook.com/docs/graph-api/reference/v3.3/object/comments
use this api for replies to the post
Method: POST
https://graph.facebook.com/860599774051206_4548643168486465/comments?access_token=APP_ID|APP_SECRET
body:
{
"message": "Thanks"
}
You need to use GET request instead POST. Look at the documentation
In my case I needed to Complete Setup

Using the graph API, is it possible to return both sizes for the user picture?

I used to do:
https://graph.facebook.com/me?fields=picture.width(100).height(100)&return_ssl_resources=1&access_token=
I want to also include the large size of the picture: picture.type(large)
Is there a way to include it in the same call? Meaning retrieving both versions.
Currently, I get this error:
{
"error": {
"message": "Syntax error \"Field picture specified more than once. This is only possible before version 2.1\" at character 76: name,first_name,last_name,picture.type(large),picture.width(100).height(100),email",
"type": "OAuthException",
"code": 2500
}
}
with : https://graph.facebook.com/mefields=picture.width(100).height(100),picture.type(large)&return_ssl_resources=1&access_token=
yes! it's possible. you can use batch requests . In this case you should use separate completion handlers for each request.
Other solution is to use field aliasing like this guy recommends : https://stackoverflow.com/a/35341593/5612119

How to deal with URLs with commas in Facebook Graph API

I would like to use Graph API to get some information about URLs.
It works like this:
http://graph.facebook.com/?ids=URL,URL2,URL3
However, when an URL contains comma, things get complicated. For
http://www.example.com/name,something
we get
http://graph.facebook.com/?ids=http%3A%2F%2Fwww.example.com%2Fname%2Csomething
what gives us:
{
"error": {
"message": "(#803) Some of the aliases you requested do not exist: something",
"type": "OAuthException",
"code": 803
}
}
What can be done with URLs to avoid such errors?
Just double-URL-encode the comma, so use %252C for it:
http://graph.facebook.com/?ids=http%3A%2F%2Fwww.example.com%2Fname%252Csomething
It might look weird, because then the Graph API identifies this URL by http://www.example.com/name\u00252Csomething - but I just tested it by pointing a like button to a URL containing a comma (un-encoded), liked it – and afterwards it showed 1 share for this URL on the Graph.