获取个人资料图片从Facebook图-API [英] Get profile picture from Facebook Graph-API

查看:184
本文介绍了获取个人资料图片从Facebook图-API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此方法来检索照片的Facebook个人资料不工作了。

  ImageView的user_picture;
 userpicture =(ImageView的)findViewById(R.id.userpicture);
 URL img_value = NULL;
 img_value =新的URL(http://graph.facebook.com/+编号+?/图像类型=大);
 位图mIcon1 = BitmapFactory.de codeStream(img_value.openConnection()的getInputStream());
userpicture.setImageBitmap(mIcon1);
 

mIcon1为null

这正常,但不发挥作用,现在,我认为Facebook已经改变了一些东西 当我检查重定向到另一个网址的URL

HTTP://graph.facebook.com/"id例如(2154847)/图片类型=大--->的https:// fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/ t1.0- 1 / s200x200 / 1480603_10201506903424508_71775 13962104534241_n.jpg

修改 解决办法:

 公共位图getPhotoFacebook(最后弦乐ID){

    点阵位图= NULL;
    最后弦乐nomimg =htt​​ps://graph.facebook.com/"+id+"/picture?type=large;
    URL IMAGEURL = NULL;

    尝试 {
        IMAGEURL =新的URL(nomimg);
    }赶上(MalformedURLException异常E){
        e.printStackTrace();
    }

    尝试 {
        HttpURLConnection的连接=(HttpURLConnection类)imageURL.openConnection();
        connection.setDoInput(真正的);
        connection.setInstanceFollowRedirects(真正的);
        connection.connect();
        InputStream中的InputStream = connection.getInputStream();
        //img_value.openConnection()。setInstanceFollowRedirects(真).getInputStream()
        位= BitmapFactory.de codeStream(InputStream的);

    }赶上(IOException异常E){

        e.printStackTrace();
    }
    返回的位图;

}
 

解决方案

试试这个:

  img_value.openConnection()。setInstanceFollowRedirects(真).getInputStream()
 

this method to retrieve the photo facebook profile does not work anymore

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 is null

it functioned normally but not now and I think that facebook has changed something when I check the URL that redirects to another 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

Edit solution :

 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;

}

解决方案

Try this:

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

这篇关于获取个人资料图片从Facebook图-API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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