2

我试图在我的应用程序中实现 facebook。我可以使用以下代码发布标题、说明和链接

Bundle postParams = new Bundle();
postParams.putString("name", "TestingApp");
postParams.putString("caption","Testing");
postParams.putString("description","ImageFilter makes your day brighter!");
postParams.putString("picture","https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");

Request request = new Request(session, "me/feed", postParams,
                HttpMethod.POST, callback);

但是我应该如何发布本地图像?

我已经尝试过这段代码,但它给出了一个空指针异常!

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();

        postParams.putByteArray("picture", byteArray);

堆栈跟踪:

05-25 18:21:22.009: E/AndroidRuntime(22803): FATAL EXCEPTION: main
05-25 18:21:22.009: E/AndroidRuntime(22803): java.lang.NullPointerException
05-25 18:21:22.009: E/AndroidRuntime(22803):    at     com.example.facebooktesting.MainActivity$2.onCompleted(MainActivity.java:147)
05-25 18:21:22.009: E/AndroidRuntime(22803):    at     com.facebook.Request$4.run(Request.java:1240)
05-25 18:21:22.009: E/AndroidRuntime(22803):    at     android.os.Handler.handleCallback(Handler.java:615)
05-25 18:21:22.009: E/AndroidRuntime(22803):    at     android.os.Handler.dispatchMessage(Handler.java:92)
05-25 18:21:22.009: E/AndroidRuntime(22803):    at     android.os.Looper.loop(Looper.java:137)
05-25 18:21:22.009: E/AndroidRuntime(22803):    at     android.app.ActivityThread.main(ActivityThread.java:4898)    
05-25 18:21:22.009: E/AndroidRuntime(22803):    at     java.lang.reflect.Method.invokeNative(Native Method)
05-25 18:21:22.009: E/AndroidRuntime(22803):    at     java.lang.reflect.Method.invoke(Method.java:511)
05-25 18:21:22.009: E/AndroidRuntime(22803):    at     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
05-25 18:21:22.009: E/AndroidRuntime(22803):    at     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
05-25 18:21:22.009: E/AndroidRuntime(22803):    at     dalvik.system.NativeStart.main(Native Method)

谢谢!

4

1 回答 1

0

me/feed 不支持上传图片,你应该发给 me/photos 代替。

请参阅此处的文档:https ://developers.facebook.com/docs/reference/api/user/#photos

您应该将位图放在“源”参数中。

您也可以只使用此方法:https ://developers.facebook.com/docs/reference/android/3.0/Request#newUploadPhotoRequest%28Session,%20Bitmap,%20Callback%29

于 2013-05-28T17:14:00.700 回答