简体   繁体   English

获取不是朋友的用户的facebook个人资料照片

[英]Get facebook profile picture of user that is not a friend

I have an android app that support facebook login too, and each logged user has a profile picture (custom, or facebook profile picture), and each user is register on my server too. 我有一个也支持Facebook登录的android应用,每个登录用户都有个人资料图片(自定义或Facebook个人资料图片),每个用户也在我的服务器上注册。 Now if i need to retrieve picture of user friends, i have no problem, because i make everithing inside app by using ProfilePictureView object of last Android Facebook SDK and friends id: 现在,如果我需要检索用户朋友的图片,则没有问题,因为我可以通过使用最后一个Android Facebook SDK的ProfilePictureView对象和朋友ID在应用程序内部进行操作:

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

If i need to retrieve facebook picture of other user, i call a php script that should return information for get picture. 如果我需要检索其他用户的facebook图片,则调用一个PHP脚本,该脚本应返回获取图片的信息。 It's a good practice to send user's id as result of script (so app retrieve picture by using ProgilePictureView), or it's better to use php sdk for get picture, encode it and sent it as result? 最好是发送用户ID作为脚本的结果(因此应用通过使用ProgilePictureView检索图片),还是最好使用php sdk获取图片,对其进行编码并作为结果发送?

If you can get user id of facebook friends, then you can get profile picture of users. 如果您可以获取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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM