Facebook graph API 'ids' variable limit - facebook

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

Related

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

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!

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.

Facebook API – Graph Search - get number of event attendees

I use Facebook API Graph Search to explore queries such as:
https://graph.facebook.com/search?q=conference&fields=name,description&type=event
I need to get a list of events by a defined query (without code, SDKs, only url, it’s important for me) with number of attendees for all of events, but this information isn’t as fields, it’s the node of an event. A list of attendees of particular event can be returned with this url:
https://graph.facebook.com/331218348435/attending
Is there any solution to get number of attending. For all events with one url? I mean the same way like fields?
Can I create more specific, complex query within url? FQL is deprecated.
EDIT:
I need this statistics of all events in one call, not for single event.
Use this call: /331218348435?fields=attending.limit(1).summary(true)
With "summary(true)", you will get a "summary" in the result:
"summary": {
"count": 1458
}
If you want to get the attendees count of several Events at once, you can use Batch Requests with up to 50 API calls in one batch: https://developers.facebook.com/docs/graph-api/making-multiple-requests

FQL equivalent to Graph API pagination

I know about the LIMIT option of FQL. But I need the same functionality like the Graph API that returns <= number of results spcified by the limit parameter but if there are more results there are links to get to these results like
"paging": {
"previous":
"https://graph.facebook.com/chickfila/posts?limit=5&since=1298995597",
"next":
"https://graph.facebook.com/chickfila/posts?limit=5&until=1293899704"
}
Can this be achieved using FQL?
Thanks in advance!
With the FQL queries, you won't get a "automated" pagination like with the Graph API. The equivalent functionality to since and until can be build by using the relevant time-based fields of the according tables in FQL.
You can have a look here for an introduction:
https://developers.facebook.com/blog/post/478/
https://developers.facebook.com/docs/graph-api/using-graph-api/#paging

Youtube REST API v3 - include statistics for video in search query result

I want to perform search queries using Youtube API v3.
What I need is to retrieve video ids and statistics for each video.
From the docs I can see that statistics is not returned for video items. If I try to ask for statistics using this query:
https://www.googleapis.com/youtube/v3/search?type=video&part=snippet,statistics&q=kittens&key={MY_KEY}
I receive an error:
{
"error": {
"errors": [
{
"domain": "youtube.part",
"reason": "unknownPart",
"message": "statistics",
"locationType": "parameter",
"location": "part"
}
],
"code": 400,
"message": "statistics"
}
}
So I guess that I need to make two requests:
Perform actual search and retrieve list of video ids.
Make API request https://developers.google.com/youtube/v3/docs/videos/list to retrieve statistics for each video.
Or maybe I'm missing something and there's a way to get statistics for videos within one search query?
In the guide, they specify "the part names that you can include in the parameter value are id and snippet" when using https://www.googleapis.com/youtube/v3/search. (statistics is not an accepted value).
So I think that you have to make two requests as you say, at least that is what I'm doing. I couldn't find any other solution. I would be interested to know if there was a workaround...
To avoid redundancy of data returned and not to use bandwidth with extra data, "video search data" and "video statistics" data are decoupled in API.
You are right about two calls.
In general, to get faster response, only use the "part" s in request that you will use in your application.