Android facebook 邀请好友请求不能使用限制参数
Android facebook invitable friends request doesn't work with limit parameter
我想获得可邀请好友的完整列表,我正在使用此代码
GraphRequest request2 = new GraphRequest(tokenObj,"/me/invitable_friends?limit=5000",null, HttpMethod.GET, new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
try {
JSONObject graphObject = graphResponse.getJSONObject();
JSONArray dataArray = graphObject.getJSONArray("data");
for (int i = 0; i < dataArray.length(); i++) {
try {
// here all that you want
JSONObject object = dataArray.getJSONObject(i);
// get facebook user id,name and picture
String str_id = object.getString("id");
String str_name = object.getString("name");
JSONObject picture_obj = object.getJSONObject("picture");
JSONObject data_obj = picture_obj.getJSONObject("data");
String str_url = data_obj.getString("url");
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
System.out.println("Exception=" + e);
e.printStackTrace();
}
}
});
request2.executeAsync();
当我 运行 这给了我一个 OAuthException
(必须使用活动访问令牌来查询有关当前用户的信息)。
有趣的是,当我删除 limit 参数并仅发送 /me/invitable_friends 时,调用有效但在带分页的数据对象中给了我默认的 25 个结果。我从一开始就需要数据对象中的所有结果,所以我需要限制参数。我有什么想法可以让它发挥作用吗?
您应该做的是将参数作为 Bundle 传递给 GraphRequest 对象。
像这样:
Bundle args = new Bundle();
args.putInt("limit", 150);
所以稍后您可以将它传递给您的 GraphRequest:
Bundle args = new Bundle();
args.putInt("limit", 150);
GraphRequest request2 = new GraphRequest(tokenObj,"/me/invitable_friends", args, HttpMethod.GET, new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
try {
JSONObject graphObject = graphResponse.getJSONObject();
JSONArray dataArray = graphObject.getJSONArray("data");
for (int i = 0; i < dataArray.length(); i++) {
try {
// here all that you want
JSONObject object = dataArray.getJSONObject(i);
// get facebook user id,name and picture
String str_id = object.getString("id");
String str_name = object.getString("name");
JSONObject picture_obj = object.getJSONObject("picture");
JSONObject data_obj = picture_obj.getJSONObject("data");
String str_url = data_obj.getString("url");
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
System.out.println("Exception=" + e);
e.printStackTrace();
}
}
});
request2.executeAsync();
没有它,你只会得到 25 个朋友(你仍然可以使用分页系统得到更多)。
我想获得可邀请好友的完整列表,我正在使用此代码
GraphRequest request2 = new GraphRequest(tokenObj,"/me/invitable_friends?limit=5000",null, HttpMethod.GET, new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
try {
JSONObject graphObject = graphResponse.getJSONObject();
JSONArray dataArray = graphObject.getJSONArray("data");
for (int i = 0; i < dataArray.length(); i++) {
try {
// here all that you want
JSONObject object = dataArray.getJSONObject(i);
// get facebook user id,name and picture
String str_id = object.getString("id");
String str_name = object.getString("name");
JSONObject picture_obj = object.getJSONObject("picture");
JSONObject data_obj = picture_obj.getJSONObject("data");
String str_url = data_obj.getString("url");
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
System.out.println("Exception=" + e);
e.printStackTrace();
}
}
});
request2.executeAsync();
当我 运行 这给了我一个 OAuthException (必须使用活动访问令牌来查询有关当前用户的信息)。 有趣的是,当我删除 limit 参数并仅发送 /me/invitable_friends 时,调用有效但在带分页的数据对象中给了我默认的 25 个结果。我从一开始就需要数据对象中的所有结果,所以我需要限制参数。我有什么想法可以让它发挥作用吗?
您应该做的是将参数作为 Bundle 传递给 GraphRequest 对象。
像这样:
Bundle args = new Bundle();
args.putInt("limit", 150);
所以稍后您可以将它传递给您的 GraphRequest:
Bundle args = new Bundle();
args.putInt("limit", 150);
GraphRequest request2 = new GraphRequest(tokenObj,"/me/invitable_friends", args, HttpMethod.GET, new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
try {
JSONObject graphObject = graphResponse.getJSONObject();
JSONArray dataArray = graphObject.getJSONArray("data");
for (int i = 0; i < dataArray.length(); i++) {
try {
// here all that you want
JSONObject object = dataArray.getJSONObject(i);
// get facebook user id,name and picture
String str_id = object.getString("id");
String str_name = object.getString("name");
JSONObject picture_obj = object.getJSONObject("picture");
JSONObject data_obj = picture_obj.getJSONObject("data");
String str_url = data_obj.getString("url");
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
System.out.println("Exception=" + e);
e.printStackTrace();
}
}
});
request2.executeAsync();
没有它,你只会得到 25 个朋友(你仍然可以使用分页系统得到更多)。