Facebook的Android SDK中如何让喜欢的数量对于一个给定页面 [英] Facebook android sdk how to get the number of likes for a given page
本文介绍了Facebook的Android SDK中如何让喜欢的数量对于一个给定页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得喜欢的号码,以便与它的ID给定的页面。
下面是href="https://graph.facebook.com/104249301622?fields=likes" rel="nofollow">图形API请求我愿与Facebook的机器人翻译的
我不明白如何做到这一点。我得到的错误,如果我尝试:
捆绑PARAMS =新包();
params.putString(域,喜欢);
请求请求=新的请求(会话,104249301622,则params,HttpMethod.GET,新Request.Callback(){
@覆盖
公共无效onCompleted(响应响应){
JSONObject的解析度= response.getGraphObject()getInnerJSONObject()。
的System.out.println(RES);
}
});
解决方案
下面是调用方法:
会话的会话= Session.getActiveSession();
捆绑PARAMS =新包();
params.putString(ID,104249301622);
params.putString(域,喜欢);
请求请求=新的请求(会话,搜索,参数,可以HttpMethod.GET,新Request.Callback(){
@覆盖
公共无效onCompleted(响应响应){
尝试 {
JSONObject的解析度= response.getGraphObject()getInnerJSONObject()getJSONArray(数据)getJSONObject(0)。;
numberOfLikes = res.getInt(喜欢);
}赶上(例外五){
}
}
});
RequestAsyncTask任务=新RequestAsyncTask(要求);
task.execute();
该请求将在下面的图形API请求。
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 make it. I get errors if I try :
Bundle params = new Bundle();
params.putString("fields", "likes");
Request request = new Request(session,"104249301622", params, HttpMethod.GET, new Request.Callback() {
@Override
public void onCompleted(Response response) {
JSONObject res = response.getGraphObject().getInnerJSONObject();
System.out.println(res);
}
});
解决方案
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.
这篇关于Facebook的Android SDK中如何让喜欢的数量对于一个给定页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文