获取 Facebook 好友位图时出现 FileNotFoundException - Android

FileNotFoundException when getting facebook friend bitmap - Android

我在获取朋友 Facebook 个人资料图片的位图时出错。这些朋友都登录了应用程序。我使用了在 Whosebug 上找到的示例来创建 AsyncTask 并加载位图,但是我还没有真正发现另一个错误 similar/relevant 到我所拥有的错误。我已经被困了一段时间了,所以感谢您的宝贵时间!

调用 AysncTask:

        new DownloadImage().execute(new MyTaskParams(friendList.get(pos).getId(), viewHolder.friendPic));

MyAsyncTask:

private class DownloadImage extends AsyncTask<MyTaskParams, Void, Void> {

    @Override
    protected Void doInBackground(MyTaskParams... params) {
        MyTaskParams im = params[0];
        int id = im.id;
        ImageView imageView = im.imageView;

        try {
            URL imageURL = new URL("https://graph.facebook.com/" + id + "/picture?type=small");
            InputStream inputStream = (InputStream) imageURL.getContent(); //line with error
            Bitmap bitmap = BitmapFactory.decodeStream(inputStream);

            imageView.setImageBitmap(bitmap);

        } catch(MalformedURLException e) {
            e.printStackTrace();
        } catch(IOException e) {
            e.printStackTrace();
        }

        return null;
    }
}

Logcat 错误:

07-05 13:14:57.312  15485-15529/com.dtfapp W/System.err﹕     java.io.FileNotFoundException: https://graph.facebook.com/2147483647/picture?type=small
07-05 13:14:57.312  15485-15529/com.dtfapp W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:197)
07-05 13:14:57.312  15485-15529/com.dtfapp W/System.err﹕ at java.net.URLConnection$DefaultContentHandler.getContent(URLConnection.java:1017)
07-05 13:14:57.312  15485-15529/com.dtfapp W/System.err﹕ at java.net.URLConnection.getContent(URLConnection.java:199)
07-05 13:14:57.312  15485-15529/com.dtfapp W/System.err﹕ at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getContent(DelegatingHttpsURLConnection.java:133)
07-05 13:14:57.312  15485-15529/com.dtfapp W/System.err﹕ at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getContent(HttpsURLConnectionImpl.java:25)
07-05 13:14:57.312  15485-15529/com.dtfapp W/System.err﹕ at com.dtfapp.FriendListArrayAdapter$DownloadImage.doInBackground(FriendListArrayAdapter.java:101)
07-05 13:14:57.312  15485-15529/com.dtfapp W/System.err﹕ at com.dtfapp.FriendListArrayAdapter$DownloadImage.doInBackground(FriendListArrayAdapter.java:93)
07-05 13:14:57.312  15485-15529/com.dtfapp W/System.err﹕ at android.os.AsyncTask.call(AsyncTask.java:288)
07-05 13:14:57.312  15485-15529/com.dtfapp W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
07-05 13:14:57.312  15485-15529/com.dtfapp W/System.err﹕ at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
07-05 13:14:57.312  15485-15529/com.dtfapp W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
07-05 13:14:57.312  15485-15529/com.dtfapp W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
07-05 13:14:57.322  15625-15625/? W/ResourceType﹕ ResTable_typeSpec entry count inconsistent: given 1, previously 1632

我也尝试过使用 facebook ProfilePictureView。它使用登录的人的 ID 工作,但在使用朋友的 ID 时不起作用。

((ProfilePictureView) rowView.findViewById(R.id.profilePicture)).setProfileId(friendList.get(pos).getIdStr());

尝试使用 facebook android sdk sdk:

/* make the API call */
new GraphRequest(
   AccessToken.getCurrentAccessToken(),
   "/{user-id}/picture",
   null,
   HttpMethod.GET,
   new GraphRequest.Callback() {
      public void onCompleted(GraphResponse response) {
          /* handle the result */
      }
   }
).executeAsync();

此外,当我在浏览器中访问时 http://graph.facebook.com/2147483647/picture 我收到此消息:

"message": "(#803) Some of the aliases you requested do not exist: 2147483647",