【问题标题】:Get profile picture from Facebook Graph-API从 Facebook Graph-API 获取个人资料图片
【发布时间】:2014-06-24 14:53:25
【问题描述】:

这种检索照片 facebook 个人资料的方法不再起作用

ImageView user_picture;
 userpicture=(ImageView)findViewById(R.id.userpicture);
 URL img_value = null;
 img_value = new URL("http://graph.facebook.com/"+id+"/picture?type=large");
 Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
userpicture.setImageBitmap(mIcon1);

mIcon1 为空

它运行正常,但现在不行,我认为 facebook 改变了一些东西 当我检查重定向到另一个 url 的 URL 时

http://graph.facebook.com/"id example(2154847)"/picture?type=large ---> https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/ t1.0- 1/s200x200/1480603_10201506903424508_71775 13962104534241_n.jpg

编辑 解决方案:

 public Bitmap getPhotoFacebook(final String id) {

    Bitmap bitmap=null;
    final String nomimg = "https://graph.facebook.com/"+id+"/picture?type=large";
    URL imageURL = null;

    try {
        imageURL = new URL(nomimg);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    try {
        HttpURLConnection connection = (HttpURLConnection) imageURL.openConnection();
        connection.setDoInput(true);
        connection.setInstanceFollowRedirects( true );
        connection.connect();
        InputStream inputStream = connection.getInputStream();
        //img_value.openConnection().setInstanceFollowRedirects(true).getInputStream()
        bitmap = BitmapFactory.decodeStream(inputStream);

    } catch (IOException e) {

        e.printStackTrace();
    }
    return bitmap;

}

【问题讨论】:

    标签: android facebook facebook-graph-api facebook-sdk-3.1


    【解决方案1】:

    试试这个:

    public static Bitmap getFacebookProfilePicture(String userID){
        URL imageURL = new URL("https://graph.facebook.com/" + userID + "/picture?type=large");
        Bitmap bitmap = BitmapFactory.decodeStream(imageUrl.openConnection().getInputStream());
    
        return bitmap;
    }
    
    Bitmap bitmap = getFacebookProfilePicture(userId);
    

    确保您使用的是 https 而不是 http。

    【讨论】:

      【解决方案2】:

      试试这个:

      img_value.openConnection().setInstanceFollowRedirects(true).getInputStream()
      

      【讨论】:

        猜你喜欢
        • 2011-04-16
        • 1970-01-01
        • 2018-11-19
        • 1970-01-01
        • 2012-01-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多