NeuraCache
NeuraCache

Reputation: 14174

using FQL in android app

I have this code which is making a call to FB api with fql query

        String fql = "SELECT name,type,page_id FROM page where page_id IN (SELECT page_id FROM page_fan WHERE uid = me())";

        Bundle parameters = new Bundle();

        parameters.putString("query", fql);
        parameters.putString("access_token",  fb.getAccessToken());

        String url = (fql != null) ? "https://api.facebook.com/method/fql.query" : "https://api.facebook.com/restserver.php";

        String response = Util.openUrl(url, "GET", parameters);

        System.out.println(response);   

Im getting response

<?xml version="1.0" encoding="UTF-8"?><fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true"/>

the query works in fb graph explorer (shows some data). I am making also couple of other reqests to graph.facebook.com with same token and they work just fine.

Cant figure out how i can make a proper fql query from android .. I have checked all examples given in SO but with no results. I have tried also encoding url using URLEncoder.encode.

Please give me few hints what i am missing.

Upvotes: 0

Views: 1442

Answers (1)

NeuraCache
NeuraCache

Reputation: 14174

ok. I figured it out. So..

First of all.. the code i posted is not compilant with what fb api says for Android. Notice using openUrl instead of Facebook code. To use it with FB there are few ways of doing it.. this is one of them

String fql = "SELECT name,type,page_id FROM page where page_id IN (SELECT page_id FROM page_fan WHERE uid = me())";

Bundle parameters = new Bundle();

parameters.putString("query", fql);
parameters.putString("method", "fql.query");
parameters.putString("access_token",  fb.getAccessToken());

String response = fb.request(parameters); 

after doing this.. as a response i got "[]" which means that the answer is arriving in json just no data was retrieved as a result to fql. For me I had to add permissions while authorizing to fb.. so that pages that user likes are retrieved

Upvotes: 2

Related Questions