获取facebook朋友位图时的FileNotFoundException - Android

时间:2015-07-05 02:27:58

标签: android facebook facebook-graph-api bitmap filenotfoundexception

我在获取朋友的Facebook个人资料图片的位图时收到错误。这些朋友都登录了应用程序。我已经使用StackOverFlow上的示例来创建AsyncTask并加载位图,但是我还没有发现与我的相似/相关的其他错误。我已经被困了一段时间,所以谢谢你的时间!

致电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$2.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$1.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());

1 个答案:

答案 0 :(得分:0)

尝试使用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",