开发者

Android and Facebook: How to use Facebook Query Language (FQL) out of Android Application

On this page facebook tells you, that you can somehow use t开发者_如何学JAVAhe Facebook-Query-Language: http://developers.facebook.com/docs/reference/fql/profile

But I just dont understand what the query looks like. On Stackoverflow I just find exapmles on how to use the FQL with PHP. But I want to use it out of and Android Application. Anybody can give me URLs or Code Examples?


Using the Facebook Android SDK, an FQL call can be implemented like this:

 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());

where FQLRequestListener extends RequestListener, just as for a Graph call.


See this link https://developers.facebook.com/docs/reference/fql , and you can go deeper because you can click on each element and see all the propreties of each element , ( exemple "album" here : https://developers.facebook.com/docs/reference/fql/album/ ).

This is an exemple of query to get the url of the pictures of an album by "album_id" :

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

This is one of the ways to call your request :

                            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);

I hope I helped, good luck! :)


This seems to work if I put it into the Browser, but I dont know how to tell the Android Facebook SDK to use this query: https://api.facebook.com/method/fql.query?query=select+pic_small+from+profile+where+id+%3D+USERID;&access_token=ACCESSTOKEN


I haven't tried it, but for calling fql you can try

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);
}

It should work.

You have to take into acount that mFacebook is an authenticated Facebook Object (of the Facebook Android SDK). Also, that the fql sould be filled with a format supported by an url. For example:

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

instead of

select pic_small from profile where id=USERID;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜