我以这种方式使用facebook sdk分享照片:
File file = new File("imagePath");
Request photoRequest = Request.newUploadPhotoRequest(session, file, new Callback() {
@Override
public void onCompleted(Response response) {
if(response.getError()==null){
try {
String id = response.getGraphObject().getInnerJSONObject().get("id").toString();
//store id
} catch (JSONException e1) {
e1.printStackTrace();
}
}
}
});
photoRequest.getParameters().putString("message", "xxx");
photoRequest.executeAsync();
现在我想得到那个id的喜欢。 我试着这样:
Session session = Session.getActiveSession();
Bundle bundle = new Bundle();
bundle.putString("id", id); // this is the id stored before
bundle.putString("fields", "likes");
Request request = new Request(session, "search", bundle, HttpMethod.GET, new Request.Callback() {
@Override
public void onCompleted(Response response) {
try {
JSONObject obj = response.getGraphObject().getInnerJSONObject();
//Obj is always -> {"data":[]}
} catch (Exception e) {
}
}
});
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
facebook API始终是{"data":[]}
。
我使用此权限:
session.requestNewPublishPermissions(new NewPermissionsRequest(act, "publish_actions","user_photos","user_status"));
可能是什么问题? 有人能帮我吗? 谢谢!
答案 0 :(得分:0)
我这样解决了:
Session session = Session.getActiveSession();
Bundle params = new Bundle();
String fql = "SELECT like_info,src_big FROM photo WHERE object_id=\""+shared.getId()+"\"";
params.putString("q", fql);
Request request = new Request(session, "/fql",params, HttpMethod.GET, new Request.Callback() {
@Override
public void onCompleted(Response response) {
String message = "Foto cancellata";
try {
JSONObject resp = response.getGraphObject().getInnerJSONObject();
JSONArray data = resp.getJSONArray("data");
if(data.length()>0){
JSONObject like_info = data.getJSONObject(0).getJSONObject("like_info");
String src = data.getJSONObject(0).getString("src_big");
if(!image.exists()){
aq.id(shared_image).image(src);
}
int count = like_info.getInt("like_count");
}else{
//PICTURE HAS BEEN DELETED
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();