通过javascript获取应用用户

时间:2011-08-25 15:06:40

标签: javascript facebook-fql

我正在尝试在javascript sdk中获取应用用户。 为什么这不起作用?

var q = FB.Data.query('SELECT uid FROM user WHERE uid IN '
            + '(SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1');

q.wait(function(resp) {
        console.log(resp);
    }
);

返回[]

但是效果很好:

var q = FB.Data.query('SELECT uid2 FROM friend WHERE uid1 = me()');
q.wait(function(resp) {
        var l = [];
        for (var i in resp) {
            l.push(resp[i].uid2)
        }
        var fql = 'SELECT uid FROM user WHERE uid IN (' + l.join(',') + ') and is_app_user = 1';
        var q1 = FB.Data.query(fql);
        q1.wait(function(resp) {
            console.log(resp);
        });
    }
);

第二个语句的问题是将所有朋友加载到浏览器中并再发出一个请求。为什么第一个声明不起作用?

2 个答案:

答案 0 :(得分:3)

尝试将is_app_user视为布尔值: (适用于我只使用fql)

var q = FB.Data.query('SELECT uid FROM user WHERE uid IN'             +'(SELECT uid2 FROM friend WHERE uid1 = me())AND is_app_user');

答案 1 :(得分:1)

试试FB.api。请参阅以下部分:旧的REST API调用:

  

FB.API也可用于调用对旧REST API的调用。对于   例如,调用links.getStats:

FB.api(
  {
    method: 'links.getStats',
    urls: 'facebook.com,developers.facebook.com'
  },
  function(response) {
    alert(
      'Total: ' + (response[0].total_count +
     。

响应1 TOTAL_COUNT));         }       );

高于+ fql.query =成功:)