2

我正在使用最新的 android-simple-facebook 库(https://github.com/sromku/android-simple-facebook),并且想要获取带有姓名、图片(个人资料图片)的朋友列表。

但我根本无法得到朋友的照片..

下面是我的代码...

在登录监听器

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 };
4

2 回答 2

0

请尝试以下权限:Permission.PUBLIC_PROFILE、Permission.USER_BIRTHDAY

于 2015-01-28T10:46:24.743 回答
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`
                        .
                        });
                    }
于 2015-09-30T23:27:04.540 回答