2011-01-29 60 views
0

我对使用任何形式的FQL都很陌生,抱歉,如果这是一个简单的问题,但我似乎无法解决它。FQL Javascript访问令牌

我有这样的代码,正尝试获取好友列表:

var query = FB.Data.query('SELECT '+response.id+', '+response.name+' FROM friendlist from user where uid=' + response.id); 

但响应我不断收到的回复是

“一个积极的访问令牌必须用于查询有关信息当前用户。”

当我拉回来从响应对象/我询问我看到我的所有信息,如位置,姓名,工作等,但我没有看到任何标记访问

的代码开始像这个:

window.fbAsyncInit = function() { 
      FB.init({appId: '12...0', status: true, cookie: true, xfbml: true}); 

      /* All the events registered */ 
      FB.Event.subscribe('auth.login', function(response) { 
       // do something with response 
       login(); 
      }); 
      FB.Event.subscribe('auth.logout', function(response) { 
       // do something with response 
       logout(); 
      }); 

      FB.getLoginStatus(function(response) { 
       if (response.session) { 
        // logged in and connected user, someone you know 
        login(); 
       } 
      }); 

我该如何获取访问令牌并提供FQL查询?

感谢您的任何建议提前!

回答

4

,你有为了做到所有类型的请求到图形API(包括FQL查询)的使用是Facebook给出后,用户在succesfuly记录的访问令牌。

如果您正在使用萤火虫在用户登录之后执行console.log(response)以查看您收到的对象。

FB.Event.subscribe('auth.login', function(response) { 
    console.log(response); 
    // do something with response 
    login(); 
}); 

应包含3个属性:permssessionstatusperms包含用户授予权限的列表,status它是当前用户的状态。重要的是session属性。这也是一个对象,其中包括access_token属性(字符串),您可以使用它来对API执行请求。

所以,您的查询可能是这样的:

var query = FB.Data.query('SELECT '+response.id+', '+response.name+' FROM friendlist from user where uid=' + response.id + '&access_token='+response.session.access_token); 

如果你想获取会话以更好的方式,使用FB.getSession,返回当前会话。更多信息here

祝你好运!

+0

谢谢你的好评! – 2011-01-29 23:58:54