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 :
Sessionsession= Session.getActiveSession();
Bundleparams=newBundle();
params.putString("id", "104249301622");
params.putString("fields", "likes");
Requestrequest=newRequest(session, "search", params, HttpMethod.GET, newRequest.Callback() {
@OverridepublicvoidonCompleted(Response response) {
try {
JSONObjectres= response.getGraphObject().getInnerJSONObject().getJSONArray("data").getJSONObject(0);
numberOfLikes = res.getInt("likes");
} catch (Exception e) {
}
}
});
RequestAsyncTasktask=newRequestAsyncTask(request);
task.execute();
The request will be translated in the following graph api request.
Solution 2:
In facebook sdk 3.8
Bundle b = newBundle();
b.putBoolean("summary", true);
newRequest(
session,
id + "/likes",
b,
HttpMethod.GET,
newRequest.Callback() {
publicvoidonCompleted(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"