I'm trying to fetch most recent posts of several pages using facebook FQL. Here is my query:
# https://developers.facebook.com/tools/explorer/145634995501895/?fql=SELECT%20message%20FROM%20stream%20WHERE%20source_id%20in%20(755751084454823%2C%20616632928446954)
SELECT message FROM stream WHERE source_id in (755751084454823, 616632928446954)
And it returns 0 results. On the other hand, sending exact same query but for a single page ID returns posts for that given query properly. So, those two queries works great:
# https://developers.facebook.com/tools/explorer/145634995501895/?fql=SELECT%20message%20FROM%20stream%20WHERE%20source_id%20in%20(616632928446954)
SELECT message FROM stream WHERE source_id in (616632928446954)
# https://developers.facebook.com/tools/explorer/145634995501895/?fql=SELECT%20message%20FROM%20stream%20WHERE%20source_id%20in%20(755751084454823)
SELECT message FROM stream WHERE source_id in (755751084454823)
I can't quite understand why it behaves like that. Any help much appreciated.
To get posts from multiple Pages, use separate calls to the feed endpoint with the Graph API. Example code for this can be found in the docs:
https://developers.facebook.com/docs/graph-api/reference/v2.6/page/feed
You can use Batch Request to make those calls faster, it will take as long as the slowest API call in the batch: https://developers.facebook.com/docs/graph-api/making-multiple-requests
FQL is deprecated and will stop working in August 2016. You canĀ“t use it in new Apps anymore.
Related
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.
I'm trying to get events in Facebook that have a certain phrase or description in them. I'd like to not have the results filtered or limited, as the phrase is fairly specific.
As an example, the phrase I'm looking for is "UMvC3" (short for Ultimate Marvel vs. Capcom 3).
That said, I could run an FQL query (and subsequently enrich with a call to the Graph API, like so):
select eid from event where contains("umvc3") and start_time >= now()
order by update_time desc
This will give me upcoming events with "umvc3" in them as well as only ones occurring in the future (I'm not concerned with past events).
However, the selection is severely limited. For example, the following isn't returned in the search results:
https://www.facebook.com/events/595137740538545/
It clearly has "umvc3" in the description text.
I can perform a search using the Graph API, but that doesn't return the above result either. Additionally, I can't filter using the Graph API on the start_time or order the results in a manner where I can stop processing the result set once I get to a certain point.
Finally, there is the Public Feed API, which will give me the entire firehose (which isn't filterable, like Twitter's, unfortunately), so I'll have to filter in real-time, which could be near impossible.
That said, am I approaching this the wrong way, or is there no way to really get a comprehensive, exact set of results from the Facebook API for events?
Note: I'm using the access_token provided by the Graph Explorer in the tools section.
The description column of Event FQL table isn't indexable, thus the freestyle search on not indexable columns won't give any result.
The results you see by running the query you suggested gives only events where the 'umvc3' is in the name column, which is indexable.
The only option is to ask facebook for fulltext indexing this column which apparently won't happen. They surely won't open any column for using clause like 'LIKE' since the query execution will take a lot of time.
And the answer from Facebook developer: https://stackoverflow.com/a/5824449/334522
I am performing a rest call to facebooks search API using type=event
e.x.
search?fields=id,name,picture,owner,description,start_time,end_time,location,venue,updated_time,ticket_uri&q=concert&type=event
I have looked through the documentation and still have a few questions about specific pagination behavior of the event search API.
If I used a broad search term like "ma" and keep querying the pagination ['next'] URL would I cycle through all facebook events starting with "ma"? Does the pagination array give any indication when there are no more results to return?.
Do these searches include past events? If so is it possible to eliminate past events using the "since" parameter?
What is the maximum for the limit parameter?
Update:
As far as I can tell the number of pages you can get from a facebook search is limited to 500. This includes pages that can be accessed via pagination. In other words a query with limit >=500 will not return a pagination url, likewise a query with limit 250 will only return one pages worth of pagination.
You will "next page" until the count of results comes less then the limit
I'm not sure if that is possible using a simple Graph Request. Maybe using FQL
I don't know exactly. But i used a 2000 limit one day. And it worked.
Other doubts you can get answers testing your resquests with this tool
https://developers.facebook.com/tools/explorer/
I am also doing the same thing like you. I am collecting public post using graph search api.
When there are no results available or you reach max limit pagination section will not be there in response. So you can always check for paging is there in json response or not something like this.
NextResult = DeserJsonFBResponce.paging != null ? DeserJsonFBResponce.paging.next : string.Empty;
I am not so sure about this with events but for public post i am able to eliminate post using science and until parameters.
Maximum for the limit parameter is 2000 per get request.
I am developing a Facebook app and I need to fetch a lot of data from users. I am concerned about limits Facebook has. I can't send queries one by one, I would soon get error 4 "API Too Many Calls". So I am wondering what is a better approach, if grouping queries into multiquery or sending them in batch. Btw I will have to use multiqueries in batch request. So here is an example :)
Suppose that USER_A and USER_B are friends so I can access them both with 1 access token.
multiquery for USER_A:
"Q0":"SELECT post_id FROM stream WHERE source_id=<USER_A>",
"Q1":"SELECT id FROM comment WHERE post_id IN (SELECT post_id FROM #Q0)"
multiquery for USER_B
"Q2":"SELECT post_id FROM stream WHERE source_id=<USER_B>",
"Q3":"SELECT id FROM comment WHERE post_id IN (SELECT post_id FROM #Q2)"
So what is better approach, grouping these 2 multiqueries into 1 bigger multiquery or putting them into a batch request? In which case will Facebook count it as 1 API call? Facebook has some limit like 100M API calls per day. So if I send my 2 multiqueries in batch / bigger multiquery, will facebook count it as 1 API call?
EDIT: by batch request i mean this https://developers.facebook.com/docs/reference/api/batch/
I am not asking if I should use FQL or Graph API, I want to know if there is a difference between sending multiqueries in batch and sending them as 1 bigger multiquery..
If you can do everything with one access_token, in my experience, a large FQL multiquery returns the results more quickly than a batch request.
Also, looking at your example query, you could cut the number of queries down by combining these:
'User_A_Comments':
"SELECT id, post_id FROM comment WHERE post_id IN (SELECT post_id FROM
(SELECT post_id FROM stream WHERE source_id=<USER_A>) )"
The advantage that a batch request would give you is you could use multiple access tokens to get this information in one shot.
Is it possible to query more than one insights metric in one API call?
For example to get the daily added likes for a page I executed the following call:
https://graph.facebook.com/_object_id_/insights/page_fan_adds_unique/day/
But I would like to have another metric, e.g., page_fan_removes_unique, included as well.
Query the insights object entirely is a possibility, but gives me too much data I don't need, thus decreases performance.
Since your question shows that you're using the Graph API, you may want to use the batch requests method: http://developers.facebook.com/docs/reference/api/batch/
You can group multiple Graph API queries together so you can just query the Insights data you need in one request.
Yes, you can run a multiple FQL query in one API call and then parse the various results.
multi query: http://developers.facebook.com/docs/reference/rest/fql.multiquery/
insights table: http://developers.facebook.com/docs/reference/fql/insights/