问题描述
我一整天都在用Facebook SDK 3.0获得我所有的Facebook好友列表
我不想使用FriendPickerFragment,因为我不想显示一个选择器,我想创建我的自己的朋友列表(显示名称和图像)。
I'm trying all day to get all my Facebook friend list using Facebook SDK 3.0I don't want to use the FriendPickerFragment, since i don't want to display a picker, i want to create my own list of friends (displaying the name and image).
根据这篇文章这是可能的,只有当一个朋友批准你的应用程序,但即使我尝试这个与我的妻子的帐户和我的,我仍然不能得到朋友列表。
According to this post Facebook friends list returns empty this is possible only if a friend approves your app, but even when i tried this with my wife's account and mine, i'm still not able to get the friend list.
任何帮助将受到高度评价,我花了这么多时间,达成死锁。
any help will be highly appreciated, I've spend so much time on this and reach a dead lock.
谢谢!
推荐答案
前提条件:
1.在Facebook上创建一个应用。
2.将android应用程序的哈希码添加到Facebook应用程序。
Precondition:
1. Create an app on facebook.
2. Add hash code of android app into facebook app.
Android应用程序:
获取权限在您的fb帐户上创建fb应用程序)
Android app:
get permission (on your fb account who created fb app)
authButton.setReadPermissions(Arrays.asList("basic_info, user_friends"));
authButton是com.facebook.widget.LoginButton(您可以参考示例应用程序了解登录名按钮工程)
authButton is com.facebook.widget.LoginButton (you can refer sample apps to find out how the login button works)
获取朋友列表的方法:
Request r = new Request(session, "/me/friends", null,HttpMethod.GET, new Request.Callback() {
@Override
public void onCompleted(Response response) {
try {
GraphObject graphObj = response.getGraphObject();
if(graphObj != null){
ArrayList<FBFriend> friendArrayList = new ArrayList<FBFriend>();
JSONObject jsonObj = graphObj.getInnerJSONObject();
JSONArray array = jsonObj.getJSONArray(DATA_NODE);
for(int i = 0; i < array.length(); i++){
JSONObject Jobj = (JSONObject)array.get(i);
String id = Jobj.getString(FBFriend.ID_NOTE);
String name = Jobj.getString(FBFriend.NAME_NOTE);
FBFriend f = new FBFriend(id, name);
friendArrayList.add(f);
}
}
}
}
});
r.executeAsync()
这篇关于Android使用SDK 3.0获取Facebook好友列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!