Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

android - How to download image from facebook Graph API

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...