【发布时间】:2018-05-23 09:17:24
【问题描述】:
我正在使用 facebook 的图形 api for android。我无法从 GraphRequest([...]).executeAsync() 中提取任何值。所以返回字符串总是空的
public String getPost(){
new GraphRequest(
AccessToken.getCurrentAccessToken(), "me?fields=friends,name", null, HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
JSONObject object = response.getJSONObject();
try {
friends = object.getJSONObject("friends").getJSONObject("summary").getString("total_count");
} catch (JSONException e) {
e.printStackTrace();
};
}
}
).executeAsync();
return friends;
}
【问题讨论】:
-
当然,这是一个异步调用。它的字面意思是
executeAsync。friends在您返回时没有设置,它设置在onCompleted中,它将在将来的某个时间调用,特别是当GraphRequest完成时(因此名称为onCompleted)。这就像问为什么你的信在放入邮箱后没有神奇地出现在你的手中。
标签: java android android-studio facebook-graph-api