android facebook image post不工作

时间:2012-11-05 13:01:41

标签: android

我使用下面的代码在Facebook上发布图片。

在下面的代码中,我将文本和图像从我的应用程序发布到facebook。当我运行此代码时,它启动progressdialogue,然后显示消息已成功发布。 但Facebook墙上没有图片和信息。

public void postToWall(final String message) {
        _progressDialog = ProgressDialog.show(_activity, "","Sharing on Facebook. Please wait.");
        new Thread(new Runnable() {
            public void run() {
                try {
                    byte[] data = null;
                    Uri selectedImage =Uri.parse(filePath);
                    String[] filePathColumn = { MediaStore.Images.Media.DATA };

                    Cursor cursor = _activity.getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
                    cursor.moveToFirst();

                    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                    String picturePath = cursor.getString(columnIndex);
                    cursor.close();                 
                    //String path = filePath+"/screeshot.jpg";

                    Bitmap bi = BitmapFactory.decodeFile(picturePath);
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    bi.compress(Bitmap.CompressFormat.PNG, 100, baos);
                    data = baos.toByteArray();
                    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
                    String accessToken = facebook.getAccessToken();
                    Bundle params = new Bundle();
                    params.putString("message", message);
                    params.putByteArray("picture", data);
                    params.putString(Facebook.TOKEN, accessToken);

                    @SuppressWarnings("unused")
                    String response1 = facebook.request("photos", params, "POST");
                    _progressDialog.cancel();
                    Message msg = new Message();
                    msg.arg1 = 0;
                    saveHandler.sendMessage(msg);
                } catch (Exception e) {
                    _progressDialog.cancel();
                    e.printStackTrace();
                }   
                catch (OutOfMemoryError e1) {
                    _progressDialog.cancel();
                    e1.printStackTrace();
                }   
            }
        }).start();
    }

以下是logcat:

11-06 06:01:41.083: E/MapActivity(571): Couldn't get connection factory client
11-06 06:01:47.372: W/System.err(571): IOException processing: 26
11-06 06:01:47.372: W/System.err(571): java.io.IOException: Server returned: 3
11-06 06:01:47.402: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
11-06 06:01:47.402: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
11-06 06:01:47.422: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
11-06 06:01:47.422: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
11-06 06:01:47.433: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
11-06 06:01:47.462: W/System.err(571):  at java.lang.Thread.run(Thread.java:1019)
11-06 06:01:48.802: W/System.err(571): IOException processing: 26
11-06 06:01:48.812: W/System.err(571): java.io.IOException: Server returned: 3
11-06 06:01:48.822: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
11-06 06:01:48.822: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
11-06 06:01:48.832: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
11-06 06:01:48.832: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
11-06 06:01:48.843: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
11-06 06:01:48.843: W/System.err(571):  at java.lang.Thread.run(Thread.java:1019)
11-06 06:01:49.562: W/KeyCharacterMap(571): No keyboard for id 0
11-06 06:01:49.562: W/KeyCharacterMap(571): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
11-06 06:01:50.153: W/System.err(571): IOException processing: 26
11-06 06:01:50.162: W/System.err(571): java.io.IOException: Server returned: 3
11-06 06:01:50.172: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
11-06 06:01:50.182: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
11-06 06:01:50.202: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
11-06 06:01:50.212: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
11-06 06:01:50.212: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
11-06 06:01:50.222: W/System.err(571):  at java.lang.Thread.run(Thread.java:1019)
11-06 06:01:51.582: W/System.err(571): IOException processing: 26
11-06 06:01:51.582: W/System.err(571): java.io.IOException: Server returned: 3
11-06 06:01:51.591: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
11-06 06:01:51.591: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
11-06 06:01:51.602: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
11-06 06:01:51.612: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
11-06 06:01:51.612: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
11-06 06:01:51.622: W/System.err(571):  at java.lang.Thread.run(Thread.java:1019)
11-06 06:01:52.922: W/System.err(571): IOException processing: 26
11-06 06:01:52.922: W/System.err(571): java.io.IOException: Server returned: 3
11-06 06:01:52.932: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
11-06 06:01:52.952: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
11-06 06:01:52.963: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
11-06 06:01:52.972: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
11-06 06:01:52.983: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
11-06 06:01:52.983: W/System.err(571):  at java.lang.Thread.run(Thread.java:1019)
11-06 06:01:54.372: D/dalvikvm(571): GREF has increased to 201
11-06 06:01:54.462: W/System.err(571): IOException processing: 26
11-06 06:01:54.472: W/System.err(571): java.io.IOException: Server returned: 3
11-06 06:01:54.472: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
11-06 06:01:54.502: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
11-06 06:01:54.502: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
11-06 06:01:54.511: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
11-06 06:01:54.523: W/System.err(571):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
11-06 06:01:54.552: W/System.err(571):  at java.lang.Thread.run(Thread.java:1019)
11-06 06:01:59.552: I/System.out(571): Root View : com.android.internal.policy.impl.PhoneWindow$DecorView@406683b0
11-06 06:03:39.962: I/MapActivity(571): Handling network change notification:CONNECTED
11-06 06:03:39.992: W/IdleConnectionHandler(571): Removing a connection that never existed!
11-06 06:03:59.922: D/dalvikvm(571): GC_CONCURRENT freed 1749K, 54% free 3709K/7943K, external 15035K/15048K, paused 12ms+8ms
11-06 06:04:41.782: D/dalvikvm(571): GC_EXTERNAL_ALLOC freed 152K, 54% free 3655K/7943K, external 14707K/15048K, paused 65ms
11-06 06:04:47.622: I/System.out(571): Root View : com.android.internal.policy.impl.PhoneWindow$DecorView@406683b0
11-06 06:06:27.991: I/MapActivity(571): Handling network change notification:CONNECTED
11-06 06:06:29.342: D/dalvikvm(571): GC_FOR_MALLOC freed 320K, 51% free 3940K/7943K, external 16047K/16796K, paused 81ms
11-06 06:06:30.552: D/dalvikvm(571): GC_FOR_MALLOC freed 285K, 51% free 4159K/8455K, external 15397K/16796K, paused 56ms
11-06 06:07:08.492: D/dalvikvm(571): GC_FOR_MALLOC freed 1172K, 46% free 4637K/8455K, external 15397K/16796K, paused 102ms
11-06 06:07:08.492: I/dalvikvm-heap(571): Forcing collection of SoftReferences for 867890-byte allocation
11-06 06:07:08.573: D/dalvikvm(571): GC_FOR_MALLOC freed 118K, 47% free 4519K/8455K, external 15397K/16796K, paused 50ms
11-06 06:07:08.573: E/dalvikvm-heap(571): Out of memory on a 867890-byte allocation.
11-06 06:07:08.622: I/dalvikvm(571): "Thread-20" prio=5 tid=9 RUNNABLE
11-06 06:07:08.622: I/dalvikvm(571):   | group="main" sCount=0 dsCount=0 obj=0x405df7b0 self=0x3fe760
11-06 06:07:08.642: I/dalvikvm(571):   | sysTid=586 nice=0 sched=0/0 cgrp=default handle=4188312
11-06 06:07:08.654: I/dalvikvm(571):   | schedstat=( 15498409993 2080675107 364 )
11-06 06:07:08.654: I/dalvikvm(571):   at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:~91)
11-06 06:07:08.662: I/dalvikvm(571):   at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:216)
11-06 06:07:08.662: I/dalvikvm(571):   at org.apache.harmony.luni.internal.net.www.protocol.http.RetryableOutputStream.write(RetryableOutputStream.java:60)
11-06 06:07:08.662: I/dalvikvm(571):   at java.io.BufferedOutputStream.write(BufferedOutputStream.java:129)
11-06 06:07:08.662: I/dalvikvm(571):   at java.io.FilterOutputStream.write(FilterOutputStream.java:105)
11-06 06:07:08.662: I/dalvikvm(571):   at com.icouponz.facebook.Util.openUrl(Util.java:203)
11-06 06:07:08.662: I/dalvikvm(571):   at com.icouponz.facebook.Facebook.request(Facebook.java:533)
11-06 06:07:08.662: I/dalvikvm(571):   at com.icouponz.FacebookHandler$2.run(FacebookHandler.java:147)
11-06 06:07:08.662: I/dalvikvm(571):   at java.lang.Thread.run(Thread.java:1019)
11-06 06:07:09.062: W/System.err(571): java.lang.OutOfMemoryError
11-06 06:07:09.082: W/System.err(571):  at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
11-06 06:07:09.122: W/System.err(571):  at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:216)
11-06 06:07:09.122: W/System.err(571):  at org.apache.harmony.luni.internal.net.www.protocol.http.RetryableOutputStream.write(RetryableOutputStream.java:60)
11-06 06:07:09.154: W/System.err(571):  at java.io.BufferedOutputStream.write(BufferedOutputStream.java:129)
11-06 06:07:09.174: W/System.err(571):  at java.io.FilterOutputStream.write(FilterOutputStream.java:105)
11-06 06:07:09.174: W/System.err(571):  at com.icouponz.facebook.Util.openUrl(Util.java:203)
11-06 06:07:09.252: W/System.err(571):  at com.icouponz.facebook.Facebook.request(Facebook.java:533)
11-06 06:07:09.284: W/System.err(571):  at com.icouponz.FacebookHandler$2.run(FacebookHandler.java:147)
11-06 06:07:09.312: W/System.err(571):  at java.lang.Thread.run(Thread.java:1019)

1 个答案:

答案 0 :(得分:1)

试试这个

String response1 = facebook.request("me/photos", params, "POST");

而不是

String response1 = facebook.request("photos", params, "POST");