我的可标记 friend 列表有问题,这是我的代码,与旧的 sdk 一起工作得很好。
public void getTaggableFriends(){
Session activeSession = Session.getActiveSession();
if(activeSession.getState().isOpened()){
new Request(
activeSession,
"/me/taggable_friends",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
GraphObject graphObject = response.getGraphObject();
if (graphObject != null) {
JSONObject jsonObject = graphObject.getInnerJSONObject();
String taggableFriendsJson = jsonObject.toString();
Gson gson = new Gson();
TaggableFriendsWrapper taggableFriendsWrapper= gson.fromJson(taggableFriendsJson, TaggableFriendsWrapper.class);
ArrayList<TaggableFriends> invitableFriends = new ArrayList<TaggableFriends>();
invitableFriends = taggableFriendsWrapper.getData();
int i;
for(i = 0; i < invitableFriends.size(); i++)
{
try
{
MainActivity.myMenu.add(invitableFriends.get(i).getName());
}
catch(Exception e){}
}
MainActivity.myMenu.add("Tot: " + i);
}else {
}
//response.get
}
}
).executeAsync();
}
}
言归正传,如何适配SDK 4.0?还是有其他方法可以做到这一点??我不知道从哪里开始,提前致谢。
最佳答案
你可以简单地把它改成
if(AccessToken.getCurrentAccessToken() != null)
{
GraphRequest graphRequest = GraphRequest.newGraphPathRequest(
AccessToken.getCurrentAccessToken(),
"me/taggable_friends",
new GraphRequest.Callback()
{
@Override
public void onCompleted(GraphResponse graphResponse)
{
//Your code
if(graphResponse != null)
{
JSONObject jsonObject = graphResponse.getJSONObject();
String taggableFriendsJson = jsonObject.toString();
Gson gson = new Gson();
TaggableFriendsWrapper taggableFriendsWrapper= gson.fromJson(taggableFriendsJson, TaggableFriendsWrapper.class);
ArrayList<TaggableFriends> invitableFriends = new ArrayList<TaggableFriends>();
invitableFriends = taggableFriendsWrapper.getData();
int i;
for(i = 0; i < invitableFriends.size(); i++)
{
try
{
MainActivity.myMenu.add(invitableFriends.get(i).getName());
}
catch(Exception e){}
}
MainActivity.myMenu.add("Tot: " + i);
}else {
}
//response.get
}
}
);
Bundle parameters = new Bundle();
parameters.putInt("limit", 5000); //5000 is maximum number of friends you can have on Facebook
graphRequest.setParameters(parameters);
graphRequest.executeAsync();
}
关于java - 在 facebook sdk 4.0+ 上获取可标记的 friend ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31235297/