How to download image from facebook Graph API

岁酱吖の 提交于 2019-11-27 04:57:23

问题


I want to download an image from facebook but my Bitmap is always null.

[
private void extractFacebookIcon(String id)
  {
    Bitmap bitmap = null;

     InputStream in = null;
     try
     {
       StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
       StrictMode.setThreadPolicy( policy );

      URL imageURL = new URL("http://graph.facebook.com/"+id+"/picture?type=large");

       in = ( InputStream) imageURL.getContent();

       bitmap = BitmapFactory.decodeStream( in );
       mFacebookIcon = bitmap;
     }
     catch(Throwable e)
     {

     }]

When I use http://graph.facebook.com/"+id+"/picture?type=large in browser, my Chrome redirects me on this link and the picture is opening and bitmap can read it.

("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-frc3/t1.0-1/c0.0.1.00.1.00/p100x100/969878_592016040843290_1511913922_t.jpg)

How to solve this problem and read the first link then bitmap was not null?


回答1:


I think it's because Facebook send your application a redirect to another URl. Have a look at http://www.mkyong.com/java/java-httpurlconnection-follow-redirect-example/ to see how you can handle redirects (HttpRedirectExample code).



来源:https://stackoverflow.com/questions/23055669/how-to-download-image-from-facebook-graph-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!