Post message to facebook wall from android fb sdk always error

人盡茶涼 提交于 2019-11-27 07:38:14

That's really weird... I have an app which uses the same syntax but it works really well. I just check the source code of the FB SDK and it seems it has changed a lot... I found this on the SDK src:

    for (String key : params.keySet()) {
        if (params.getByteArray(key) != null) {
                dataparams.putByteArray(key, params.getByteArray(key));
        }
    }

So, you try to do this:

Bundle params = new Bundle();

params.putByteArray("message", "Test".getBytes());
params.putByteArray("name", "American Virgin".getBytes());
params.putByteArray("link", "http://bit.ly/12345".getBytes());
params.putByteArray("description", "A Freshman College Girl on a scholarship from an ...".getBytes());
params.putByteArray("picture", "http://xxx/MOV1026.jpg".getBytes());

mAsyncRunner.request("me/feed", params, "POST", new TestRequestListener());
Chris Banes

The fix is:

if (parameters.get(key) instanceof byte[]) {

instead of

if (parameters.getByteArray(key) != null) {

on line 63 of Util.java.

And

if (params.get(key) instanceof byte[]) {

instead of

if (params.getByteArray(key) != null) {

on line 155 of Util.java.

For some strange reason, on Samsung Nexus S (perhaps other devices too) it returns a String, not a byte[].

I think the error message is quite clear... "Key picture expected byte[] but value was a java.lang.String."

The value for the key "picture" in your Bundle params should be a byte array, not a String.

edit: Didn't read Cristian's answer. I'm pretty sure you should pass along the actual image data, not the filename in bytes. But I could be wrong.

another edit: Yeah, so I'd downvote my own answer if I could, but it seems I didn't even read the question properly. The error happens not just for picture, so I have no idea what's wrong...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!