Facebook Graph API v1.0 data size limit for JSON return object? - facebook

Does Facebook's Graph API have some sort of limit on the size of the JSON object that is returned from its queries?
When I request a lot of a user's friends information, I sometimes get an error code of 1 - unknown error. This happens when I run the following query for a user that has a lot of Facebook friends (200 and up)
me/friends/?fields=id,name,gender,birthday,cover,significant_other,languages,education,work,
checkins.limit(1).fields(place,id,created_time),
likes.limit(5).fields(id,name,created_time),
statuses.limit(5).fields(message,updated_time),
movies.limit(5).fields(name,created_time,id),
music.limit(5).fields(name,created_time,id),
books.limit(5).fields(name,created_time,id),
games.limit(5).fields(name,created_time,id),
interests.limit(5).fields(name)
I tried this on the Graph Explorer and it returned this error
{
  "error": "Request failed"
}
If I run the same request with fewer friends (125 or so), I get back all the data I expect.
It seems like the error is happening because the number of bytes in the JSON that is returned is larger than some threshold, but I haven't seen anything in the docs to corroborate this.
Would what cause this error to happen? Has anyone faced this issue before? Any ideas of how to mitigate this?
Solutions I've Considered
Limit the number of friends returned, and if the error still occurs, lower that limit for the next batch, and if still the error occurs, lower the limit again, etc - this solution isn't ideal but will probably work for most cases
Split up the queries into multiple requests - this approach would increase the API calls significantly (risking throttling) since it is no longer part of one paged request
Use FQL instead of Graph API - I haven't done enough research into this, but I believe that I would have to query each entity (likes, checkins, etc) one at a time which would increase the API calls significantly and risk throttling
In the end, all of these solutions are still subject to same Unknown Error to some degree since I can't predict the size of the object that will be returned (a status message could be a few words or a few paragraphs). It would be ideal to get a handle as to why this error is happening before going off and implementing a work around.
Thanks in advance!

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.

Facebook API - reduce the amount of data you're asking for, then retry your request for 1 row

I have the following logic for my ad insights request:
If Facebook asks me to reduce the amount of data I'm requesting, I half the date range. If the date range is the same, I half the limit.
It gets to the point I send this request:
https://graph.facebook.com/v3.2/{account}/insights?level=ad&time_increment=1&limit=1&time_range={"since":"2019-03-29","until":"2019-03-29"}&breakdowns=country&after=MjMwNwZDZD
But I still get that error:
Please reduce the amount of data you're asking for, then retry your request
There is no more reducing I can do.
Note, that this only happens sometimes.
One way to avoid the error is when you only request 1 item (limit=1) to start splitting the fields and request half the fields in each request.
Another way is to run an async report, which should not have such a low time limit.
Official Facebook API team response:
It looks like you are requesting a lot of fields, this is likely the
cause of this error. This will cause the request to time-out.
Could you try using asynchronous requests as described here:
https://developers.facebook.com/docs/marketing-api/insights/best-practices/#asynchronous?
Async requests have a much longer time limit, this will likely resolve
your issue.

FQL/GRAPH Api Logic

I have a logic problem I can't seem to solve (might be possible).
Example:
I am inside 100 facebook groups
I need the 10 lastest posts of EACH group I am in.
That's pretty much it but I can't seem to find a way to do this without making a foreach loop calling the api over and over again, if I had a couple hundred more groups it would be impossible.
PS: I'm using FQL atm but am able to use graph, I've coded this in like 3 different ways but no success.
This is the farthest I could get:
SELECT actor_id,source_id FROM stream WHERE source_id IN (select gid from group_member where uid = me())
It only returns from one page, maybe there's no way to return all of this without a foreach asking for each groups 10 lastest messages.
There's no need to use FQL of batching. This can be done with a simple Graph API request IMHO:
GET /me/groups?fields=id,name,feed.fields(id,message).limit(10)
This will return 10 posts for each of your groups. In case there too much data to be returned, try setting the limit parameter for the base query as well:
GET /me/groups?fields=id,name,feed.fields(id,message).limit(10)&limit=20
Then, you'll get a next field in the result JSON. By calling the URL contained in this field, you'll get your next results. Do this until the result is empty, then you reached the end.
You can use batch calls, described here https://developers.facebook.com/docs/graph-api/making-multiple-requests/
Using batch requests, you can request upto 50 calls in one go. Note than batch request doesn't increase the rate limits, so if you make 50 requests in batch, it will be considered as 50 calls, and not one. However you will get the response in a shorter time.
If you think you're making too many calls, you should put some delay in between calls and avoid rate limiting.

why the offset and limit

Facebook simulator test https://graph.facebook.com/me/feed?limit=50 return to the 16, switched to https://graph.facebook.com/me/feed?limit=1&offset=9, but no data is returned.
If offset changed to 8,it will return a data. How this is going, who can help me?
The amount of data is enough, but it can not use limit and offset to display all the data.
This facebook blog post explains how the limit and offset parameters work and also the limitations of them.
Use time-based paging instead of “offset” to ensure you are getting back as many results as possible with each call. For these Graph API connections, use the “since” and “until” parameters.

FQL query response randomly omits some results

I'm trying to make a simple "only status updates, nothing else" app (since FB doesn't seem too interested in this sort of thing). However, my queries seem to omit some results:
"select status_id,uid,time,message from status where uid in (select uid2 from friend where uid1= $my_id) ORDER BY time DESC LIMIT 25", for instance, when I last tested it, only returned 21 results (and yes, I've got enough friends who have made enough updates that there are definitely more than 25 historical statuses).
This is with the PHP API, by way of Heroku, but I've had similar issues for a while, going back to before FBML was deprecated, with basically the same query.
I haven't tested enough to determine absolutely that this is the case, but it seems only to return one status per user (if Bob posted six updates, it only returns his newest status and ignores the previous ones).
Is this a known issue/bug? Any workarounds?
facebook trades accuracy for performance it has been always the case , so it usually returns a limited number of results per query
It's probably because a user has not given access for a friends apps to access their posts. Apparently making an FQL request, facebook does the initial request, including your limit param. Then it filters the list removing anything that you don't have permissions to see. Hence receiving less than 25 results.