如何获得用户的Facebook个人资料图片在Facebook的SDK的Andr​​oid [英] How to get facebook profile picture of user in facebook SDK Android

查看:148
本文介绍了如何获得用户的Facebook个人资料图片在Facebook的SDK的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Facebook的3.6 SDK。我想从图形用户个人资料图片,上一次我得到的图像,但现在它返回null位图。

I used facebook 3.6 sdk . i want to get profile picture from graph user , last time i got image but now it returns null Bitmap.

我用下面的code

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

当我使用直接链接,然后它的作品。

When i use direct link then it works.

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

我refered这也图形API参考

推荐答案

自动重定向自动工作在原有的和重定向协议是一样的。

Auto redirection works automatically when original and redirected protocols are same.

所以,尝试从 HTTPS 而不是 HTTP 加载图像: https://graph.facebook.com/USER_ID/picture ;由于图片的URL为 https://fbcdn-profile-a.akamaihd.net/ ......

So, try to load images from https instead of http : "https://graph.facebook.com/USER_ID/picture"; since image's url is "https://fbcdn-profile-a.akamaihd.net/...."

然后 BitmapFactory.de codeStream 应重新工作。

这篇关于如何获得用户的Facebook个人资料图片在Facebook的SDK的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆