3

发送一批请求时,无法使用适用于 android 的 facebook 图形 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();
4

1 回答 1

3

找到了答案。

您需要为每个单独的请求设置回调以获取与批处理相关的回调,因为 onBatchCompleted 回调将在所有 per-Request 回调被调用后被调用。

        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);

        }
于 2013-05-03T08:35:03.310 回答