2011-01-29 64 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