1

I have just put implemented Facebook connect on my web-site using the JavaScript SDK. Now I would like to process an fql query.

So I have two questions:

  1. Is it possible using only JavaScript fql as "SELECT id, name FROM user WHERE uid IN (SELECT uid1 FROM friends WHERE uid2=me())" ?

  2. Because when I tried some PHP SDK code using the facebook doc

PHP:

$app_id = 'MY_ID';
$app_secret = 'MY_APP_SECRET';
$my_url = 'POST_AUTH_URL';
$code = $_REQUEST["code"];

$_REQUEST["code"] is quite normally not recognized and I don't know what is the "'POST_AUTH_URL'" because I didn't use the PHP SDK to process the Facebook-connect. Does anyone have an idea?

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
epsilones
  • 11,279
  • 21
  • 61
  • 85

3 Answers3

14

Using method: 'fql.query' is part of the deprecated REST API.

A better, future-proof way IMHO is to send your queries against the Graph API:

FB.api("/fql?q={your urlencoded query}", callback() { … } );
CBroe
  • 91,630
  • 14
  • 92
  • 150
9

Using the JavaScript SDK you can easily execute an FQL query -

FB.api(
  {
    method: 'fql.query',
    query: 'SELECT name FROM user WHERE uid=me()'
  },
  function(response) {
    alert('Your name is ' + response[0].name);
  }
);

Don't forget to request all the permissions you need before executing any queries...


Reference - https://developers.facebook.com/docs/reference/javascript/

Lix
  • 47,311
  • 12
  • 103
  • 131
0

Sorry I can't comment yet but to clarify this helpful answer; what worked for me was formatting the FQL API call the same way I would a Graph API call with {fields: "ex1,ex2"}:

var fqlRequest = "SELECT name FROM user WHERE uid = me()";
FB.api("/fql",{q:fqlRequest}, function(response){
    // do cool stuff with response here
});

Note that I did NOT have to URL encode the string and it worked fine for me (I had used encodeURI(fqlRequest) before and it returned an unexpected % error).

Also remember to quote literals if you use them:

var id = "1234567890";
var fqlRequest = "SELECT name FROM user WHERE uid = ' " + id + " ' ";
Community
  • 1
  • 1
BoombaleOsby
  • 321
  • 4
  • 7
  • Do you really want spaces before/after the `id`? I seems to me you should have `"... uid = '" + id + "'";` which I know is harder to read, but with the spaces it will likely fail, right? – Alexis Wilke Aug 06 '16 at 20:00