我正在使用最新的android-simple-facebook库 (https://github.com/sromku/android-simple-facebook) 并希望得到名字,图片(个人资料图片)的好友列表。
但我根本无法得到朋友的照片..
下面是我的代码......
在LoginListener
private OnLoginListener mOnLoginListener = new OnLoginListener() {
@Override
public void onFail(String reason) {
Log.w(TAG, "Failed to login");
}
@Override
public void onException(Throwable throwable) {
Log.e(TAG, "Bad thing happened", throwable);
}
@Override
public void onThinking() {
// show progress bar or something to the user while login is
// happening
}
@Override
public void onLogin() {
PictureAttributes pictureAttributes = Attributes.createPictureAttributes();
pictureAttributes.setType(PictureType.NORMAL);
pictureAttributes.setHeight(500);
pictureAttributes.setWidth(500);
// change the state of the button or do whatever you want
Properties properties = new Properties.Builder()
.add(Properties.ID)
.add(Properties.LAST_NAME)
.add(Properties.PICTURE, pictureAttributes)
.add(Properties.BIRTHDAY).build();
mSimpleFacebook.getFriends(properties, mOnFriendsListener);
}
@Override
public void onNotAcceptingPermissions(Permission.Type type) {
}
};
和朋友听众
// get friends listener
private OnFriendsListener mOnFriendsListener = new OnFriendsListener() {
@Override
public void onFail(String reason) {
// insure that you are logged in before getting the friends
Log.w(TAG, reason);
}
@Override
public void onException(Throwable throwable) {
Log.e(TAG, "Bad thing happened", throwable);
}
@Override
public void onThinking() {
// show progress bar or something to the user while fetching profile
Log.i(TAG, "Thinking...");
}
@Override
public void onComplete(List<Profile> friends) {
for (Profile profile : friends) {
mLists.add(new FriendItem(profile.getName(), profile.getPicture()));
}
mAdapter = new FriendsListAdapter(getActivity());
mFriendsList.setAdapter(mAdapter);
}
};
但是配置文件对象只包含id和name。 我应该用异步调用get方法吗? 或者我用getFriends()方法做的其他事情。
许可列表如下:
Permission[] permissions = new Permission[] {
Permission.BASIC_INFO,
Permission.USER_CHECKINS,
Permission.USER_EVENTS,
Permission.USER_GROUPS,
Permission.USER_LIKES,
Permission.USER_PHOTOS,
Permission.USER_VIDEOS,
Permission.FRIENDS_EVENTS,
Permission.FRIENDS_PHOTOS,
Permission.PUBLISH_STREAM };
答案 0 :(得分:0)
Plz尝试以下权限: Permission.PUBLIC_PROFILE, Permission.USER_BIRTHDAY
答案 1 :(得分:0)
出于某种原因,你必须覆盖onLogin中的onComplete()方法来处理你要求的东西。
响应将包含您在权限构建器中要求的所有内容。
我花了很多时间来弄清楚这一点。希望它有所帮助:)
final OnLoginListener onLoginListener = new OnLoginListener() {
@Override
public void onLogin(String accessToken, List<Permission> acceptedPermissions, List<Permission> declinedPermissions) {
OnProfileListener onProfileListener = new OnProfileListener() {
@Override
public void onComplete(final Profile response) {
super.onComplete(response);
.
. // Your code in here`enter code here`
.
});
}