Facebook Graph API - IG User Insights - Get audience_* metrics - facebook

I am trying to get audience_city, audience_country, audience_gender_age, audience_locale metrics from FB graph API IG user insights endpoint: https://developers.facebook.com/docs/instagram-api/reference/ig-user/insights
The request I am making:
curl --location --request GET 'https://graph.facebook.com/v10.0/17841411377776842/insights?access_token=...&metric=audience_city&period=lifetime&since=1614639600&until=1614812400'
and the error returned:
{
"error": {
"message": "(#100) (audience_city) metric supports querying data only till yesterday",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "APrDtw-8BzaJSbu4F9Q-RA5"
}
}
The since and until timestamps are set to accordingly 2, 4 March 2021 - so definitely I am not querying "too fresh" data.
The same request for another metric like online_followers is working like a charm.
Has anyone met a similar issue and been able to overpass it?

Maybe you have figured it out by now, but in case someone lands in here, let's help them:
Quoting the docs: https://developers.facebook.com/docs/instagram-api/reference/ig-user/insights#metrics-and-periods
Metrics that support lifetime periods will have results returned in an array of 24 hour periods, with periods ending on UTC−07:00. audience_* metrics do not support since and until range parameters
So basically when using metrics with the prefix audience_ you do not need to specify the since/until parameters. The error message is a bit disorienting.
Update:
The API documentation has been updated since the question was posted and includes the audience_* specification. I did not check that, my bad.
Thank you #Jan for the update and letting me know!

Related

API error when requesting full size data from Alphavantage

I am working on analysing some historical stock market data for Australian shares. I am using Alphavantage as my API to get the actual data.
My problem relates specifically to the TIME_SERIES_DAILY function with FULL outputsize. For some shares, I receive an error message in response to an API call:
https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=SUL.AUS&outputsize=full&apikey=XXXXXXXXXXXXXX
{
"Error Message": "Invalid API call. Please retry or visit the documentation (https://www.alphavantage.co/documentation/) for TIME_SERIES_DAILY."
}
If I change the outputsize argument to 'compact' it works but only returns a subset of data I am after.
The bizarre thing is that the full size response works for about 60% of the stocks I am after. After a bit of trial and error, I deduce that the API returns an error for specific shares everytime and not others.
I presume that there may be some feature about these specific shares that causes it to fail - I just don't know what.
This is a known error with Alpha Vantage. See here for more details.
When there is an issue with data past 100 days, instead of returning bad data, it scraps the return as to not throw off algos.

How to get ALL communities from DSpace rest api

Using the endpoint:
GET https://mydspace.org/rest/communities/
I seem to only get 100 results returned. I can't see any options in the documentation to return more. How do I do this?
Most of the DSpace rest endpoints support a limit parameter. I suppose that there is some maximum size that you can request, but the limit should be able to go higher than 100.
https://demo.dspace.org/rest/communities?limit=500
If you still are unable to retrieve everything in one request (or if you timeout), you can paginate through the results in your code.
https://demo.dspace.org/rest/communities?limit=100
https://demo.dspace.org/rest/communities?offset=100&limit=100
https://demo.dspace.org/rest/communities?offset=200&limit=100
There is an endpoint (in DSpace 6) that will allow you to retrieve the ids and handles for the full hierarchy.
https://demo.dspace.org/rest/hierarchy
It's not very prominent, but pagination of REST responses is documented at https://wiki.duraspace.org/display/DSDOC6x/REST+API#RESTAPI-RESTEndpoints just above "Index / Authentication".

How can I retrieve a large number of DELETED Campaigns, Adsets, Ads?

Task
I'm trying to retrieve all Ad Campaign, Adsets and Ads from various accounts associated with our Business Manager.
Issue
The specific endpoints that I'm accessing are:
https://graph.facebook.com/v2.8/act_xxxxxxxxxxxxx/campaigns
https://graph.facebook.com/v2.8/act_xxxxxxxxxxxxx/adsets
https://graph.facebook.com/v2.8/act_xxxxxxxxxxxxx/ads
When I query some of these accounts for all Campaigns using the filter parameter,
[{'operator': 'IN',
'field': 'ad.effective_status',
'value': [
'ACTIVE',
'PAUSED',
'DELETED',
'PENDING_REVIEW',
'DISAPPROVED',
'PREAPPROVED',
'PENDING_BILLING_INFO',
'CAMPAIGN_PAUSED',
'ARCHIVED',
'ADSET_PAUSED']}]
the Facebook API always returns this error:
{"error":{"code":1,"message":"Please reduce the amount of data you're asking for, then retry your request"}}
Troubleshooting
I've used various values for the filter parameter such as 1, 25, 50, 100, 500.
I've tried limiting the date using the date_preset parameters (this seems irrelevant).
I've tried limiting the queries by filtering down to individual campaigns by including {'operator': 'IN','field':'campaign.id','value':['xxxxxxxxxxxxx']} as an additional filter in the filter parameter.
I've attempted batch requests and querying the /insights endpoint, but I haven't had one work yet.
Other Details
When I only include ACTIVE campaigns in the filter, the query works. This has allowed me to deduce that the DELETED campaigns are the problem. In other words, these accounts have a ton of DELETED campaigns.
I'm making my requests using Postman Version 5.0.0 (5.0.0).
I imagine if I can figure out how to get the Campaigns, the Adsets and Ads will be similar. How do I go about resolving this?
The reason is that the API does not actually support querying for deleted objects for certain endpoints. I tried to obtain all campaigns for a certain account and this is the response.
Method: GET
Path:
https://graph.facebook.com/v2.10/act_XXXX/campaigns
Params: {'effective_status': '["ACTIVE","PAUSED","DELETED","ARCHIVED"]', 'fields': 'id,name,status', 'summary': 'true'}
Response:
{
"error": {
"code": 100,
"is_transient": false,
"error_subcode": 1815001,
"error_user_msg": "Requesting for deleted objects is not supported in this endpoint.",
"error_user_title": "Cannot Request for Deleted Objects",
"message": "Invalid parameter",
"type": "OAuthException",
"fbtrace_id": "FYDwMABcwxj"
}
}
After looking at the documentation I discovered this
https://developers.facebook.com/docs/marketing-api/best-practices/storing_adobjects
And here they state
If you keep the deleted object id, you can continue to retrieve the
stats or object details by individually querying the object ID.
However you cannot retrieve the deleted objects as a connection object
from a non deleted node/object.

Find the count of the like on Graph Api

I use facebook graph api and I encountered a problem relating to likes.
My request:
My goal is to find the count of the like. but the query timeout. What is the solution?
Thanx
My goal is to find the count of the like
So you only want the overall number of likes, the counter, but not the individual likes?
Then you should ask for the summary via field expansion:
/{page_id}/feed?fields=likes.limit(0).summary(1)
For each feed item, you will get a likes data structure that looks like this:
"likes": {
"data": [
],
"summary": {
"total_count": 12345
}
}
Try the options below.
Uncheck all the boxes and make the request again, if you give no error, go marking one by one until you find the problem.
Try not to use the limit (999999) is very, I've had problems trying to get as much information in one query page.
Make sure your access token created this with all the necessary permissions to your query.
I confess that I have never seen this error in the Graph API, is very generic and it is difficult to give you a more accurate suggestion.

Facebook graph API 'ids' variable limit

I'm making API calls to retrieve simple data from Facebook pages:
/[page_id]?fields=likes,talking_about_count,checkins
I know I can get multiple results by providing multiple ids using the 'ids' variable:
/?ids=[page_id],[page_id],[page_id]&fields=likes,talking_about_count,checkins
My problem is that I don't how many ids I can retrieve simultaneously. I know the limit for batched request is 50, but I can't find the documentation for the 'ids' variable.
UPDATE: it seems like this limit has been removed on version 2.0 of the graph API, but I am still looking for an official answer.
I used Graph Explorer to list all post ids on a page. It returned me 140 posts.
I then sent those 140 posts to the Graph API using the ids parameter and got this in return:
{
"error": {
"message": "(#100) Too many IDs. Maximum: 50. Provided: 140.",
"type": "OAuthException",
"code": 100
}
}
So the answer is currently 50.
Facebook Graph API Limit Documentation