你需要做的是建立一个JSONArray为您的要求,然后再转换JSONArray为字符串您把它送到使用HTTPS POST服务器之前。对于每个请求,根据Facebook API(先前发布的链接)创建JSONObject,然后将所有这些JSONObjects添加到JSONArray,并使用Facebook SDK的内置“openUrl”方法(位于SDK内的Util类中)。
下面是我为检验批的一个小例子。
JSONObject me_notifications = new JSONObject();
try {
me_notifications.put("method", "GET");
me_notifications.put("relative_url", "me/notifications");
} catch (JSONException e) {
e.printStackTrace();
Log.e(TAG, e.getMessage());
}
JSONObject me_home = new JSONObject();
try {
me_home.put("method", "GET");
me_home.put("relative_url", "me/home");
} catch (JSONException e) {
e.printStackTrace();
Log.e(TAG, e.getMessage());
}
JSONObject me_friends = new JSONObject();
try {
me_friends.put("method", "GET");
me_friends.put("relative_url", "me/friends");
} catch (JSONException e) {
e.printStackTrace();
Log.e(TAG, e.getMessage());
}
JSONArray batch_array = new JSONArray();
batch_array.put(me_home);
batch_array.put(me_notifications);
batch_array.put(me_friends);
new FacebookBatchWorker(this, mHandler, false).execute(batch_array);
而且FacebookBatchWorker仅仅是一个的AsyncTask(只需使用任何线程你想真的...)。重要的部分是HTTPS请求,我使用facebook SDK中已有的那些,就像这样。
的“PARAMS [0]的ToString()”是JSONArray我发送到的AsyncTask,我们需要转换为用于实际发布请求的字符串。
/* URL */
String url = GRAPH_BASE_URL;
/* Arguments */
Bundle args = new Bundle();
args.putString("access_token", FacebookHelper.getFacebook().getAccessToken());
args.putString("batch", params[0].toString());
String ret = "";
try {
ret = Util.openUrl(url, "POST", args);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
希望你能得到的东西这...
希望更新后的信息让事情变得清晰 – Kavitha 2011-06-16 22:09:12