Fql.query
From Facebook Developers Wiki
Contents |
[edit] Description
Evaluates an FQL (Facebook Query Language) query.
Warning: If you use JSON as the output format, you may run into problems when selecting multiple fields with the same name or with selecting multiple "anonymous" fields (for example, SELECT 1+2, 3+4 ...).
[edit] Parameters
| Required | Name | Type | Description | |
| required | api_key | string | The application key associated with the calling application. | |
|---|---|---|---|---|
| session_key | string | The session key of the logged in user. | ||
| call_id | float | The request's sequence number. Each successive call for any session must use a sequence number greater than the last. We suggest using the current time in milliseconds, such as PHP's microtime(true) function. | ||
| sig | string | An MD5 hash of the current request and your secret key, as described in the authentication guide. | ||
| v | string | This must be set to 1.0 to use this version of the API. | ||
| query | string | The query to perform, as described in the FQL documentation. | ||
| optional | format | string | Desired response format. Either XML (default) or JSON. | |
| callback | string | Name of a function to call. This is primarily to enable cross-domain JavaScript requests using the <script> tag, also known as JSONP, and works with both the XML and JSON formats. The function will be called with the response passed as the parameter. |
[edit] Example Queries
| SELECT name, affiliations FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=211031) AND "Facebook" IN affiliations.name AND uid < 10 |
| SELECT src, caption, 1+2*3/4, caption, 10*(20 + 1) FROM photo WHERE pid IN (SELECT pid FROM photo_tag WHERE subject=211031) AND pid IN (SELECT pid FROM photo_tag WHERE subject=204686) AND caption |
[edit] Example Return XML
| <?xml version="1.0" encoding="UTF-8"?> <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true"> <user> <name>Mark Zuckerberg</name> <affiliations list="true"> <affiliation> <nid>50431648</nid> <name>Facebook</name> <type>work</type> <status/> <year/> </affiliation> <affiliation> <nid>16777217</nid> <name>Harvard</name> <type>college</type> <status>Undergrad</status> <year/> </affiliation> </affiliations> </user> <user> <name>Chris Hughes</name> <affiliations list="true"> <affiliation> <nid>50431648</nid> <name>Facebook</name> <type>work</type> <status/> <year/> </affiliation> </affiliations> </user> <user> <name>Dustin Moskovitz</name> <affiliations list="true"> <affiliation> <nid>50431648</nid> <name>Facebook</name> <type>work</type> <status/> <year/> </affiliation> <affiliation> <nid>16777217</nid> <name>Harvard</name> <type>college</type> <status>Undergrad</status> <year/> </affiliation> </affiliations> </user> </fql_query_response> |
| <?xml version="1.0" encoding="UTF-8"?> <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true"> <photo><src>http://photos-923.ak.facebook.com/ip002/v61/188/75/206412/s206412_31508923_7923.jpg</src> <caption>celebrating 23 years of ari's life at the one and the oasis.</caption> <anon>2.5</anon> <caption>celebrating 23 years of ari's life at the one and the oasis.</caption> <anon>210</anon> </photo> <photo> <src>http://photos-447.ak.facebook.com/ip005/v40/164/17/202965/s202965_30849447_4635.jpg</src> <caption>Liar's Dice...</caption> <anon>2.5</anon> <caption>Liar's Dice...</caption> <anon>210</anon> </photo> <photo> <src>http://photos-480.ak.facebook.com/ip005/v29/188/75/206412/s206412_30452480_140.jpg</src> <caption>the crew. (RishDAWG!)</caption> <anon>2.5</anon> <caption>the crew. (RishDAWG!)</caption> <anon>210</anon> </photo> <photo> <src>http://photos-103.ak.facebook.com/ip001/v12/188/75/206412/s206412_30325103_6676.jpg</src> <caption>group photo!!!!</caption> <anon>2.5</anon> <caption>group photo!!!!</caption> <anon>210</anon> </photo> <photo> <src>http://photos-399.ak.facebook.com/ip001/v10/188/75/206412/s206412_30191399_9134.jpg</src> <caption>someone is particularly happy to be in this picture</caption> <anon>2.5</anon> <caption>someone is particularly happy to be in this picture</caption> <anon>210</anon> </photo> <photo> <src>http://photos-716.ak.facebook.com/ip007/v16/129/99/204686/s204686_30190716_7256.jpg</src> <caption>One of the most extravagant.</caption> <anon>2.5</anon> <caption>One of the most extravagant.</caption> <anon>210</anon> </photo> </fql_query_response> |
[edit] Response
This method returns data that very closely resembles the returns of other API calls like users.getInfo. This is not a coincidence - in fact, many of the other API functions are simply wrappers for FQL queries. Note that it preserves the order of the fields in your SELECT clause and that it can contain multiple elements with the same name depending on how you structure the query.
[edit] Error Codes
| Code | Description | |
| 1 | An unknown error occurred. Please resubmit the request. | |
|---|---|---|
| 2 | The service is not available at this time. | |
| 4 | The application has reached the maximum number of requests allowed. More requests are allowed once the time window has completed. | |
| 5 | The request came from a remote address not allowed by this application. | |
| 100 | One of the parameters specified was missing or invalid. | |
| 101 | The API key submitted is not associated with any known application. | |
| 102 | The session key was improperly submitted or has reached its timeout. Direct the user to log in again to obtain another key. | |
| 103 | The submitted call_id was not greater than the previous call_id for this session. | |
| 104 | Incorrect signature. | |
| 601 | Error while parsing FQL statement. | |
| 602 | The field you requested does not exist. | |
| 603 | The table you requested does not exist. | |
| 604 | Your statement is not indexable. | |
| 605 | The function you called does not exist. | |
| 606 | Wrong number of arguments passed into the function. |
[edit] Notes
Additional example queries are included in the description of the other API functions.
