获取不是朋友的用户的Facebook个人资料图片



我有一个支持Facebook登录的Android应用程序,每个登录的用户都有一个个人资料图片(自定义或Facebook个人资料图片),每个用户也在我的服务器上注册。现在,如果我需要检索用户朋友的图片,我没有问题,因为我通过使用最后一个Android Facebook SDK和朋友ID的ProfilePictureView对象在应用程序内做任何事情:

fb_image = (ProfilePictureView) view.findViewById(R.id.fb_friend_thumbnail);
fb_image.setProfileId(friend_id);

如果我需要检索其他用户的Facebook图片,我会调用一个php脚本,该脚本应该返回获取图片的信息。将用户的 ID 作为脚本的结果发送是一种很好的做法(因此应用程序使用 ProgilePictureView 检索图片),或者最好使用 php sdk 获取图片,对其进行编码并作为结果发送?

如果你能得到Facebook好友的用户ID,那么你就可以得到用户的头像。

  Request request = Request.newMeRequest(session,
            new Request.GraphUserCallback() {
                @Override
                public void onCompleted(GraphUser user, Response response) {
                    // If the response is successful
                    try {
                        if (session == Session.getActiveSession()) if (user != null) {
                            String fbFirstName = user.getFirstName();
                            String fbLastName = user.getLastName();
                            String dateOfBirth = user.getBirthday();
                            String userId=user.getId();
                            URL image_url=new URL("https://graph.facebook.com/"+ user.getId()+ "/picture?type=small");
                            Bitmap bitmap=null;
                            bitmap= BitmapFactory.decodeStream(image_url.openConnection().getInputStream());
                            String fbEmail = user.asMap().get("email").toString();
                            Session.getActiveSession()
                                    .closeAndClearTokenInformation();
                            getActivity().finish();
                        }
                    }
                        catch(Exception e){
                            Log.e(Constants.TAG_EXCEPTION, e.toString());
                        }
                    }
            });
    request.executeAsync();
}

最新更新