Using facebook javascript sdk to process fql query

六眼飞鱼酱① 提交于 2019-11-29 16:40:34

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() { … } );

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/

BoombaleOsby

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 + " ' ";
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!