2010-12-16 42 views

回答

0

我還沒有嘗試過,但調用FQL你可以試試

public String request(String fql) throws FileNotFoundException, MalformedURLException, IOException { 
Bundle parameters = new Bundle 
parameters.putString("format", "json"); 
parameters.putString("query", fql); 
parameters.putString("access_token", mFacebook.getAccessToken()); 

if (mFacebook.isSessionValid()) { 
    params.putString("access_token", mFacebook.getAccessToken()); 
} 
     String url = (fql != null) ? "https://api.facebook.com/method/fql.query" : "https://api.facebook.com/restserver.php"; 
return Util.openUrl(url, "GET", params); 
} 

它應該工作。

你必須考慮到mFacebook是一個認證的Facebook對象(的Facebook Android SDK)。另外,fql應該填充url支持的格式。例如:

select+pic_small+from+profile+where+id+%3D+USERID; 

,而不是

select pic_small from profile where id=USERID; 
2

使用Facebook Android SDK,一個FQL通話可以實現這樣的:

String query = "SELECT name FROM user WHERE uid = me()"; 
Bundle params = new Bundle(); 
params.putString("method", "fql.query"); 
params.putString("query", query); 
mAsyncFacebookRunner.request(null, params, new FQLRequestListener()); 

其中FQLRequestListener延伸RequestListener,只是作爲一個圖形呼叫。

+1

@Pascal Klein只是一個友好的提醒:如果你發現答案回答了你的問題,請接受它。 – 2012-12-16 04:46:19

+0

hackBook鏈接不可用..你可以讓我知道其他的FQL Demo鏈接..謝謝 – 2014-02-27 13:54:50

+0

@Mario似乎hackBook已經不存在了。我刪除了答案中的鏈接。也許新的github FB示例項目包含一個示例? – 2014-02-27 22:49:36

1

看到這個鏈接https://developers.facebook.com/docs/reference/fql,你可以更深入,因爲你可以點擊每個元素,並看到每個元素的所有特性,(例如「專輯」在這裏:https://developers.facebook.com/docs/reference/fql/album/)。

這是查詢的個例由「album_id」拿到相冊的圖片的URL:

String fqlQuery = "SELECT src FROM photo WHERE album_object_id="+ <your_album_id>; 

這是調用您的要求的方法之一:

      Bundle params = new Bundle();        
          params.putString("format", "json"); 
          params.putString("query", fqlQuery); 
          params.putString("access_token", fbAccessToken); 
          Session session = Session.getActiveSession(); 
          Request request = new Request(session, "/fql", 
            params, HttpMethod.GET, 
            new Request.Callback() { 
             public void onCompleted(
               Response response) { 
              Log.i(TAG, "Got results: " 
                + response.toString()); 
             } 
            }); 
          Request.executeBatchAsync(request); 

我希望我幫助,祝你好運! :)