gpt4 book ai didi

java - 我想从 facebook api 请求多个页面名称和页面照片

转载 作者:行者123 更新时间:2023-12-01 13:13:14 25 4
gpt4 key购买 nike

所以我试图从 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();

}


}

我确信我做错了,我应该如何解决这个问题?

最佳答案

Request req = new Request(
session,
"/{page-id}/feed",
null,
HttpMethod.GET,
new Request.Callback(){
public void onCompleted(Response response) {

try
{
GraphObject go = response.getGraphObject();
JSONObject jso = go.getInnerJSONObject();
JSONArray arr = jso.getJSONArray( "data" );
String name = " ";
String picture = " ";

for ( int i = (arr.length()-1); i >=0; i-- )
{
JSONObject json_obj = arr.getJSONObject( i );


name = json_obj.getString( "name");
picture = json_obj.getString("picture");
//...

}
txtMessage.setText(name);
//imgFeed is ImageView


Picasso.with(getActivity()).load(picture).into(imgFeed);

}
catch ( Throwable t )
{
t.printStackTrace();
}
}
});req.executeAsync();

这将从墙上的帖子中获取名称和图像...还记得下载 picasso 库并将其添加到您的项目中。

希望这有帮助

关于java - 我想从 facebook api 请求多个页面名称和页面照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22672932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com