我怎样才能让朋友使用安卓-简单-脸书库



我正在使用最新的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 和名称。我应该使用异步调用 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 };

出于某种原因,您必须在 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`
                        .
                        });
                    }

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

相关内容

  • 没有找到相关文章

最新更新