0
所以我試圖從facebook api請求所有的名字和所有的照片鏈接。 但我不斷收到錯誤,因爲異步任務已在運行。我想請求facebook api上的多個頁面名稱和頁面照片
public void getPages(){
AsyncTask<String, Void, String[]> GL = j.new GetLikes().execute(extras.getString("PIC"));
try {
likes = GL.get();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int i=0;i<Json.PI;i++){
final int j = i;
final Request photo = new Request(
null,
"/" + PhotoId,
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
GraphObject graphObject = response.getGraphObject();
JSONObject jsonObject = graphObject.getInnerJSONObject();
try {
PageInfo[j][1] = (String) jsonObject.get("picture");
Log.i("PICTURE", PageInfo[j][1]);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
);
final Request photos = new Request(
null,
"/"+PageId+"/photos/uploaded",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
GraphObject graphObject = response.getGraphObject();
JSONObject jsonObject = graphObject.getInnerJSONObject();
try {
JSONArray array = jsonObject.getJSONArray("data");
JSONObject object = (JSONObject) array.get(0);
Log.i("PHOTOID", (String) object.get("id"));
PhotoId = (String) object.get("id");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.i("PNAME", String.valueOf(response));
photo.executeAsync();
}
}
);
Request PageID = new Request(
null,
"/"+PageId,
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
GraphObject graphObject = response.getGraphObject();
JSONObject jsonObject = graphObject.getInnerJSONObject();
try {
PageInfo[j][0] = jsonObject.getString("name");
Log.i("PNAME", PageInfo[j][0]);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
photos.executeAsync();
}
}
);
PageID.executeAsync();
}
}
我敢肯定即時通訊做得這一切都是錯誤的,我該如何處理這個問題?