Adapting Page Post Queries from Facebook API 2.5 -> 2.7 - facebook

I'm currently grabbing post-level insights from my FB page 2.5 for a dashboard to see how well recent posts are doing; a simple benchmark/performance manager dashboard that does all the querying on the front-end [js api].
The calls/procedure I used to use:
1) Get my posts
[page_id]/posts
2) Then loop them and pull the post data from two synchronous calls
// A) gets all the metrics
[page_post_id]/insights
// B) gets other data critical for front-end display
[page_post_id]/?fields=type,created_time,permalink_url
This works perfectly, and for as far as FB says, it will work until June 2018 (I think).
My problem is that the call for step 2-A fails because I believe it requires a separate call for each metric.
That 2-A call returns:
{
"error": {
"message": "Invalid query",
"type": "OAuthException",
"code": 3001,
"error_subcode": 1504028,
"is_transient": false,
"error_user_title": "No Metric Specified",
"error_user_msg": "No metric was specified to be fetched. Please specify one or more metrics to be fetched and try again.",
"fbtrace_id": "XXXXXXXXX"
}
}
Am I wrong?
Is there something that could be done better or would I need to call each metric independently?
I'll eventually need to get there in 2 years but better to address it early and get my teeth on that fresh, new data.
Thanks in advance everyone!
Cheers!

I used a similar setup in Python and ran into the same issue.I've discovered that the {metric} parameter can actually be an array of values.
In Facebook's Graph Explorer I managed to get multiple metrics in one call using this syntax:
<post_id>/insights/["post_stories","post_storytellers"]
You can add additional metrics to the array as needed.
As far as I can tell this feature is not (properly) documented in the Graph API documentation pages, so I'm not sure this usage is intended or not.

Related

Got error on invoking the IBM Softlayer "getCpuMetricImage" rest API

I have an active IBM Softlayer account. I am getting the error as
{"error":"One of types passed is not in the proper container.",
"code":"SoftLayer_Exception_Metric_Tracking_Object_InvalidDataType"}
when trying to fetch the cpu metric image using the below rest API with valid Virtual_Guest_Id and Snapshot_Range":
"api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/<Virtual_Guest_Id>/getCpuMetricImage/<Snapshot_Range>"
But I am getting the proper response while fetching the memory metric image using the similar rest API listed below:
"api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/<Virtual_Guest_Id>/getMemoryMetricImage/<Snapshot_Range>"
First of all your REST request is wrong it should something like this:
POST https://$USERNAME:$APIKEY#api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/$VSIID/getCpuMetricImage
PAYLOAD:
{
"parameters": ["day","9/2/2017"]
}
Second the method is not working currently I am going to report it, but I do not have idea when they are going to fix it.
Another thing to point out is that the Softlayer's control portal do not use that method to display the graph, so is likely that the image returned by the method and the graph in the portal are going to be different. If you want the same inforamtion I recomend you to use the same method see this forum for more information:
SoftLayer API CPU usage mismatch
The method in the forum above will return you the data of the graph and then you are going to need to represent that information in a graph using your own code.
Regards

How do I get the campaigns list through the ads API on Facebook?

I am trying to get the campaigns list from the Graph API Explorer. I'm using the request found at https://developers.facebook.com/docs/marketing-api/reference/ad-account/campaigns/.
GET /v2.8/{ad-account-id}/campaigns HTTP/1.1
Host: graph.facebook.com
I'm' business manager and admin of the page used for ads. I found the AD_ACCOUNT_IDs using the following request on the Graph API Explorer.
GET /v2.8/me/businesses HTTP/1.1
Host: graph.facebook.com
I choosed the one which had the higher privileges.
The error reported when submitting the first request for campaigns is:
{
"error": {
"message": "Unsupported get request. Object with ID '1015359838XXXXXX' 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,
"fbtrace_id": "DLyfwGbM8fi"
}
}
What's wrong?
Thanks in advance,
Mattia
#Ryan's answer saved my day. It may sound stupid/silly but I was doing this mistake and I was just stuck at it.
Going through the FB docs for using the Marketing Apis.
I was trying to build the custom audience, this is how the curl request looks like -
One of the basic things to keep in mind while using the Marketing API is, almost all the APIs ask for these two things -
1) ACCESS_TOKEN
2) AD_ACCOUNT_ID
For people who are just starting with the FB Marketing API or somehow stuck in finding these values, I will just tell you how to get these values, so that you don't have to waste your time as I did.
So for getting the ACCESS_TOKEN, go to your app dashboard then click Add Product and then select Marketing API. Once you added the product, this is how the screen should look like -
Now just check the permissions and click on the Get Token button, a token would be generated. Just copy the token in some file and save it.
Now for getting the AD_ACCOUNT_ID value, just go to the Adverts Manager page -
The number that is written inside the red box in you Adverts Manager page is your AD_ACCOUNT_ID.
The final step would be to go back to you app dashboard again, Settings > Advanced
Click on Ads API and then enter the AD_ACCOUNT_ID here. Thats it, you have finished the Access and Authentication process for using the marketing API via your App.
Now comes the part where I was doing the silly mistake. The curls request looks like this -
curl \
-F 'name=My new CA' \
-F 'subtype=CUSTOM' \
-F 'description=People who bought from my website' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/customaudiences
First I replaced ACCESS_TOKEN with its value.
Then instead of replacing only the <AD_ACCOUNT_ID> I replaced the whole string act_<AD_ACCOUNT_ID>, with the AD_ACCOUNT_ID value.
So I was getting this error while making request to the API which was -
{"error":{"message":"Unsupported post request. Object with ID '120574219' 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,"fbtrace_id":"YsSvKKwgLMQ"}}
I don't know why I made this mistake but I am sure this is one of the common mistake others are doing too. Since the response from FB was misleading, I wasted a lot of my time in understanding and reading on the API permissions and authentications.
Hope this article was helpful and save your time.
I similarly was having problems trying to retrieve a list of all campaign IDs within an ad account.
I already am able to retrieve campaign data by ID, so I obviously have permissions already.
But the Facebook error message is misleading.
When retrieving an ad account (in order to then display its campaigns or whatever you want within it), you need to retrieve by its ID prepended with 'act_'.
E.g you could request /act_123456789000001234/campaigns instead of /123456789000001234/campaigns.
Thanks so much to #Jan Sommer at https://stackoverflow.com/a/39974857/470749.

Facebook Test User error

I use facebook login in my app and have tests for it. I use the /{app-id}/accounts/test-users endpoint to create users for my tests but the endpoint fails with the very generic
{
"error": {
"message": "An unknown error has occurred.",
"type": "OAuthException",
"code": 1
}
}
(which says the API is possibly down). I tried this with 3 different appids/secrets, both with using app_id|app_secret as the token and with a token from the get token endpoint. I also tested this on the Graph Api Explorer and it's giving me the same error. It was working fine but then it suddenly stopped.
What I want to know is 1. is it down? and 2. if not, what did i do wrong or what changed since yesterday?
+1 this also started to me yesterday mid-morning, with code and an FB app which had been working previously and was unchanged.
When I look at https://developers.facebook.com/apps/FB_APP_ID/roles/test-users/, I can see the new users.
So the call is "working" in that new users are being created, but it is broken in that we get a 500 and we don't get an access_token.
I don't have an answer yet.
I ran into a similar problem last week. After long hours of debugging I found out that I would get this same error every time I tried to create multiple test users with the same name simultaneously (i.e. when running tests in multiple threads).
So instead of setting custom a user name I don't even use the name field and I just let Facebook generate one. This way everything works fine. Seriously. I love Facebook API so much. :)
Hope this helps someone.

facebook graph api returns empty data array

I wanted to get the events for a closed group (which has tons of events) via the facebook graph api, but I only got
{
"data": [
]
}
in the Graph API Explorer even though I was using an auth token with user_events enabled. Just to be sure, I enabled every single permission for the token but got the same result.
what am I doing wrong?
I think I just found the answer to my problem; there was nothing wrong!
What I thought were events coming up were actually events that happened in the past, shown in the group/events page; I guess those aren`t aren't accessible.
I think I'll settle with using FQL as offered as a solution in this question.

List of Facebook error codes

I'm looking for a list of all Facebook can return when you try to fetch infos using Graph API. Can anyone help?
Facebook returns a 400 HTTP error, and a JSON content like:
{
"error": {
"type": "OAuthException",
"message": "Invalid OAuth access token signature."
}
}
I'm searching the different returns of the same kind it is possible to get.
Facebook used to have this published somewhere, but for whatever reason it was removed. But you can find the full list here:
http://www.takwing.idv.hk/tech/fb_dev/faq/general/gen_10.html
There seems to be a list now for the errors.
I posted answer for the same question here: Facebook Graph API error code list
(I found the list here https://developers.facebook.com/docs/graph-api/using-graph-api/error-handling)
In case Takwing's copy ever comes down, here's another copy: http://fbdevwiki.com/wiki/Error_codes
These codes were primarily for the REST API, but they do also come up with the Graph API. Some of the Graph API calls have underlying FQL calls that return the FQL error codes. And the direct FQL queries are still part of the currently accepted API.
Update: I'm trying to keep this list up-to-date. Please feel free to make changes as you encounter new errors.
I am trying to keep an updated list of error codes based on previous outdated information.
You can find the repo here http://github.com/phwd/fbec and it has been updated with Test User and Credit Error codes from the Facebook Documentation.
Currently looking for the constant name for "Error Code 2500" and some error descriptions may have changed. I hope to keep on top of this.
There is an official error code page, now:
https://developers.facebook.com/docs/marketing-api/error-reference/
It still doesn't look comprehensive...