Fql.query
From Facebook Developer Wiki
Contents |
Description
Evaluates an FQL (Facebook Query Language) query. For more complex queries where you want to use the results of one query in another query without making another API call, consider using fql.multiquery.
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 ...).
Parameters
| Required | Name | Type | Description | |
| required | api_key | string | The application key associated with the calling application. If you specify the API key in your client, you don't need to pass it with every call. | |
|---|---|---|---|---|
| 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. If you specify the call ID in your client, you don't need to pass it with every call. | ||
| sig | string | An MD5 hash of the current request and your secret key, as described in the How Facebook Authenticates Your Application. Facebook computes the signature for you automatically. | ||
| v | string | This must be set to 1.0 to use this version of the API. If you specify the version in your client, you don't need to pass it with every call. | ||
| query | string | The query to perform, as described in the FQL documentation. | ||
| optional | session_key | string | The session key of the logged in user, or the session key provided when the user granted your application the offline_access extended permission. The session key is automatically included by our PHP client. Depending upon the table you are querying, you might get only certain information without a session key. For example, querying the user table is like calling users.getInfo without a session key -- you can query only on a few fields. You can query the page_fan table without a session to return the list of Pages the user has fanned that would be visible to a logged-out user. | |
| format | string | The desired response format, which can be either XML or JSON. (Default value is XML.) | ||
| 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. |
Example Queries
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.
Example Return XML
Error Codes
For a complete list of error codes, see 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. |
Notes
- Additional example queries are included in the articles for other API functions.
- You can call this method using a session secret, and not the application secret (for example, for a Facebook Connect site or desktop application).
