如何在facebook SDK Android中获取用户的facebook个人资料图片

Tul*_*hod 8 android facebook facebook-graph-api facebook-android-sdk

我使用facebook 3.6 sdk.我想从图形用户获取个人资料图片,上次我有图像,但现在它返回null位图.

我使用以下代码

private void onSessionStateChange(Session session, SessionState state,
            Exception exception) {
        if (session.isOpened()) {
            Request.newMeRequest(session, new Request.GraphUserCallback() {
                @Override
                public void onCompleted(GraphUser user, Response response) {
                    if (user != null) {
                        try {
                            URL imgUrl = new URL("http://graph.facebook.com/"
                                    + user.getId() + "/picture?type=large");

                            InputStream in = (InputStream) imgUrl.getContent();
                            Bitmap  bitmap = BitmapFactory.decodeStream(in);
                            //Bitmap bitmap = BitmapFactory.decodeStream(imgUrl      // tried this also
                            //.openConnection().getInputStream());
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }).executeAsync();
        }
    }
Run Code Online (Sandbox Code Playgroud)

当我使用直接链接然后它工作.

imgUrl = new URL("https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-ash3/t39.2365-6/851558_160351450817973_1678868765_n.png");
Run Code Online (Sandbox Code Playgroud)

我也提到了这个图谱API参考

Sah*_*tal 25

当原始协议和重定向协议相同时,自动重定向会自动生效.

因此,尝试从https而不是http:" https://graph.facebook.com/USER_ID/picture " 加载图像; 因为图片的网址是" https://fbcdn-profile-a.akamaihd.net/ ...."

然后BitmapFactory.decodeStream应该再次工作.