Facebook Android Sdk How To Get The Number Of Likes For A Given Page
I would like to get the number of likes for a given page with its id. Here is the graph api request I would like to translate with the facebook-android-sdk. I cannot figure how to
Solution 1:
Here is the method to call :
Session session = Session.getActiveSession();
Bundle params = new Bundle();
params.putString("id", "104249301622");
params.putString("fields", "likes");
Request request = new Request(session, "search", params, HttpMethod.GET, new Request.Callback() {
@Override
public void onCompleted(Response response) {
try {
JSONObject res = response.getGraphObject().getInnerJSONObject().getJSONArray("data").getJSONObject(0);
numberOfLikes = res.getInt("likes");
} catch (Exception e) {
}
}
});
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
The request will be translated in the following graph api request.
Solution 2:
In facebook sdk 3.8
Bundle b = new Bundle();
b.putBoolean("summary", true);
new Request(
session,
id + "/likes",
b,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
String s=response.toString();
}
}
).executeAsync();
And you will hace the field "total_count" in the Json response.
Post a Comment for "Facebook Android Sdk How To Get The Number Of Likes For A Given Page"