Facebook Methods description: fql.query

anna_150.jpg

Evaluates an FQL (Facebook Query Language) query. More information about FQL is available here. Additional example queries are included in the description of the other API functions.

Parameters

 

string api_key The application key associated with the calling application.
string session_key The session key of the logged in user.
float call_id 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.
string sig An MD5 hash of the current request and your secret key, as described in the authentication guide.
string v This must be set to 1.0 to use this version of the API.
string format Optional - desired response format. Either “XML” (default) or “JSON”.
string callback Optional - wrap the response inside a function call. This is primarily to enable cross-domain javascript requests using the <script> tag, sometimes known as “JSONP“. This works with both XML and JSON.
string query The query to perform, as described in the FQL documentation.

Be warned that if using JSON as the output format, you may run into problems when selecting multiple fields with the same name or with selecting multiple “anonymous” fields (e.g. SELECT 1+2, 3+4 …).

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

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>
      <affiliation>
        <nid>67108894</nid>
        <name>San Francisco, CA</name>
        <type>region</type>
        <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>
      <affiliation>
        <nid>16777217</nid>
        <name>Harvard</name>
        <type>college</type>
        <status>Alumnus/Alumna</status>
        <year>2006</year>
      </affiliation>
      <affiliation>
        <nid>67108869</nid>
        <name>Washington, DC</name>
        <type>region</type>
        <status/>
        <year/>
      </affiliation>
      <affiliation>
        <nid>67108894</nid>
        <name>San Francisco, CA</name>
        <type>region</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>
      <affiliation>
        <nid>16777219</nid>
        <name>Stanford</name>
        <type>college</type>
        <status>Staff</status>
        <year/>
      </affiliation>
      <affiliation>
        <nid>67108894</nid>
        <name>San Francisco, CA</name>
        <type>region</type>
        <status/>
        <year/>
      </affiliation>
      <affiliation>
        <nid>67108896</nid>
        <name>Silicon Valley, CA</name>
        <type>region</type>
        <status/>
        <year/>
      </affiliation>
      <affiliation>
        <nid>67109006</nid>
        <name>Ocala, FL</name>
        <type>region</type>
        <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>

Response

This method returns data that very closely resembles the returns of other API calls like facebook.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.

Error codes

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 down not exist.
606 Wrong number of arguments passed into the function.

Source page

Tags: ,

Related Post

No Comments

No comments yet.

Comments RSS TrackBack Identifier URI

Leave a comment