相同的建议。
我有两个请求,其中第一个请求的输出是第二个请求的输入。因此,我提出了一个获取当前位置页面ID的请求,这是第二个帖子请求的输入,该请求使用此页面ID检查我当前位置。
这是第一个获得请求的代码:
Request.GraphPlaceListCallback callback = new Request.GraphPlaceListCallback() {
@Override
public void onCompleted(List<GraphPlace> places, Response response) {
try {
placePageID = places.get(0).getInnerJSONObject().getString("id");
Log.i("MyFBClient", "Place id is " + placePageID);
} catch (JSONException e) {
e.printStackTrace();
}
}
};
Request requestPlacePageID = Request.newPlacesSearchRequest(session,
myLocation, /* TODO: Error handling may be required */
1000,
10,
null,
callback
);
requestPlacePageID.setBatchEntryName("PlacePageIDReq");
requestPlacePageID.setBatchEntryOmitResultOnSuccess(false);
这是第二个请求的代码:
Bundle postParams = new Bundle();
postParams.putString("message", " My Text Message ");
postParams.putString("place",/* Here is exactly my problem, how can I reference a place id from the previous GET request?? */ );
JSONObject coordinates = new JSONObject();
try {
coordinates.put("latitude", "30.0380279");
coordinates.put("longitude","31.2405339");
Log.i("MyFBClient", "adding latitude and longitude");
} catch (JSONException e) {
e.printStackTrace();
Log.w("MyFBClient","Exception while adding latitude and longitude");
}
Request requestPublishStory = new Request(session, /*"me/feed"*/ "me/checkins", postParams,
HttpMethod.POST, publishCallback);
requestPublishStory.setBatchEntryDependsOn("PlacePageIDReq"); /* Here I add dependency */
最后,我创建了批处理请求并异步执行:
RequestBatch myBatch = new RequestBatch();
myBatch.add(requestPlacePageID);
myBatch.add(requestPublishStory);
myBatch.executeAsync();
再次,我不知道如何将我的第一个请求输出作为第二个请求输入的输入?任何人都可以与Facebook高级GUID
我想你会做类似的事情:
postParams.putString("place", "{result=PlacePageIDReq:$.data.0.id}");
请参阅https://developers.facebook.com/docs/graph-api/making-making-multiple-requests/#operations有关更多详细信息。