2014-05-11 38 views
1

我是Facebook SDK中的新成員。我想從Facebook獲取PostID和消息。這是我的android代碼。Android Fql查詢異常

private void Fql() { 
    String fqlQuery = "SELECT post_id, message FROM stream WHERE source_id='100008169074385' "; 
    Bundle params = new Bundle(); 
    params.putString("q", fqlQuery); 
    Session session = Session.getActiveSession(); 
    Request request = new Request(session, "/fql", params, HttpMethod.GET, 
      new Request.Callback() { 
       public void onCompleted(Response response) { 
        MessageBox(response.toString()); 
       } 
      }); 
    Request.executeBatchAsync(request); 
} 

但代碼給了我一個例外:「需要訪問令牌來請求這個資源」。 請任何人給我一些解決方案

+0

好像你的會話無效,因爲看起來沒有訪問令牌添加到請求中。 – Tobi

回答

1

這可能會幫助你。

private void Fql() { 


     String fql = "SELECT link_id, title, summary, url from link WHERE owner = 'YourID'"; 

     Bundle parameters = new Bundle(); 

     parameters.putString("query", fql); 
     parameters.putString("method", "fql.query"); 



     Session session = Session.getActiveSession(); 
     parameters.putString("access_token", session.getAccessToken()); 

     String response = null; 
     try { 
      response = fb.request(parameters); 
     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     MessageBox(response); 

    }