android-RequestBatch.Callback onBatchCompleted()未调用
作者:互联网
发送一批请求时,无法使用Android的facebook graph API库.
运行此代码时未得到回调:
RequestBatch requestBatch = new RequestBatch(requests);
requestBatch.addCallback(new com.facebook.RequestBatch.Callback() {
@Override
public void onBatchCompleted(RequestBatch batch) {
Log.e(LOG_TAG, "onBatchCompleted()");
}
});
requestBatch.executeAsync();
解决方法:
找到了答案.
您需要为每个单独的请求设置回调以获取与批处理相关的回调,因为onBatchCompleted回调将在调用所有按请求的回调之后被调用.
for (String friend : friends) {
MyLog.d(LOG_TAG, "Adding request for " + friend.getInterestFbId());
String graphPath = friend + "/feed";
Request request = new Request(session, graphPath, null, HttpMethod.GET);
Bundle params = new Bundle();
params.putString("fields",
"id,"+
"name,"+
"username,"+
"feed,");
request.setParameters(params);
// THIS IS VITAL OR THE BATCH CALLBACK WILL NEVER ARRIVE
request.setCallback(new com.facebook.Request.Callback() {
@Override
public void onCompleted(Response response) {}
});
requests.add(request);
}
标签:facebook,android,facebook-graph-api 来源: https://codeday.me/bug/20191123/2066919.html