首页 文章

获取不是朋友的用户的facebook Profiles 照片

提问于
浏览
0

我有一个支持facebook登录的Android应用程序,每个登录用户都有 Profiles 图片(自定义或Facebook Profiles 图片),每个用户也在我的服务器上注册 . 现在,如果我需要检索用户朋友的图片,我没有问题,因为我通过使用上一个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来获取图片,对其进行编码并将其作为结果发送?

1 回答

  • 1

    如果您可以获得Facebook好友的用户ID,那么您可以获得用户的 Profiles 图片 .

    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();
    }
    

相关问题