views:

264

answers:

4

I have problem with fb sdk for Android (downloaded from http://github.com/facebook/facebook-android-sdk). Tried to post wall but always get error (permission already set and logged in to fb)

here is the code snippet onClick function, i made small modifications on their sample code:

Bundle params = new Bundle();

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

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

From DDMS i get the following error:

    09-16 18:55:28.372: WARN/Bundle(14392): Key picture expected byte[] but value was a java.lang.String.  The default value <null> was returned.
09-16 18:55:28.414: WARN/Bundle(14392): Attempt to cast generated internal exception:
09-16 18:55:28.414: WARN/Bundle(14392): java.lang.ClassCastException: java.lang.String
09-16 18:55:28.414: WARN/Bundle(14392):     at android.os.Bundle.getByteArray(Bundle.java:1220)
09-16 18:55:28.414: WARN/Bundle(14392):     at com.facebook.android.Util.openUrl(Util.java:153)
09-16 18:55:28.414: WARN/Bundle(14392):     at com.facebook.android.Facebook.request(Facebook.java:295)
09-16 18:55:28.414: WARN/Bundle(14392):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:209)
09-16 18:55:28.422: WARN/Bundle(14392): Key message expected byte[] but value was a java.lang.String.  The default value <null> was returned.
09-16 18:55:28.432: WARN/Bundle(14392): Attempt to cast generated internal exception:
09-16 18:55:28.432: WARN/Bundle(14392): java.lang.ClassCastException: java.lang.String
09-16 18:55:28.432: WARN/Bundle(14392):     at android.os.Bundle.getByteArray(Bundle.java:1220)
09-16 18:55:28.432: WARN/Bundle(14392):     at com.facebook.android.Util.openUrl(Util.java:153)
09-16 18:55:28.432: WARN/Bundle(14392):     at com.facebook.android.Facebook.request(Facebook.java:295)
09-16 18:55:28.432: WARN/Bundle(14392):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:209)
09-16 18:55:28.452: WARN/Bundle(14392): Key format expected byte[] but value was a java.lang.String.  The default value <null> was returned.
09-16 18:55:28.472: WARN/Bundle(14392): Attempt to cast generated internal exception:
09-16 18:55:28.472: WARN/Bundle(14392): java.lang.ClassCastException: java.lang.String
09-16 18:55:28.472: WARN/Bundle(14392):     at android.os.Bundle.getByteArray(Bundle.java:1220)
09-16 18:55:28.472: WARN/Bundle(14392):     at com.facebook.android.Util.openUrl(Util.java:153)
09-16 18:55:28.472: WARN/Bundle(14392):     at com.facebook.android.Facebook.request(Facebook.java:295)
09-16 18:55:28.472: WARN/Bundle(14392):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:209)

Any sollutions?

+1  A: 

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());
Cristian
Hi Christian, thanx for your answer. The code actually works, it took a long time to appear on my fb wall, but the warning messages still exists. You are right, the problem was in cast operation. if i put 'POST', the parameters must in byte array not in String. Tried to use byte array but the errors still appear because another parameters (graph path, token key still in string)
Lorensius W. L. T
A: 

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...

benvd
okay no problem, it seems the problem was in sdk. i'll try to manually edit it..thanx for your answer benvd...
Lorensius W. L. T
A: 

Hi there, I am having the same (similar) problem: I am getting "Key Access_token" expected ... and the same thing that you.

My question is: I am not passing a key with name "access_token" so why I am getting this? First I thought I should pass it, but still does not work, the code is:

private Facebook mFacebook; private AsyncFacebookRunner mAsyncRunner;

mFacebook.authorize(this, APP_ID, PERMISSIONS, new DialogListener()... Bundle params = new Bundle(); params.putByteArray("method", "photos.upload".getBytes()); params.putByteArray("picture", data); //data is byte []

//and finally

mAsyncRunner.request("me/feed", params, "POST", new SampleUploadListener());

any idea what I am doing wrong?

DarkWizard
A: 

The fix is:

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

instead of:

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

on lines 63 & 153 of Util.java.

Chris