如何从Facebook的图形API下载图片下载图片、图形、Facebook、API

2023-09-12 10:40:29 作者:场罚期间

我想下载从Facebook的形象,但我的位图总是空。

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

     }]

当我使用 http://graph.facebook.com/+编号+/照片?类型=大在浏览器中,我的浏览器重定向我这个链接,画面是开放和位图可以读取它。

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?

推荐答案

我想这是因为Facebook发送您的应用程序重定向到另一个URL。看一看 http://www.mkyong.com/java/ Java的HttpURLConnection的遵循重定向的例子/ 就看你如何处理重定向(Htt的predirectExample code)。

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