Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid post picture to Facebook wall
    primarykey
    data
    text
    <p>I am trying to post a picture to my wall on Facebook. I have managed logging in and posting text to the wall. However, when I try posting the picture, nothing happens.</p> <p>I am using the <a href="https://github.com/facebook/facebook-android-sdk" rel="noreferrer">Android Facebook SDK</a>.</p> <p>Here is what I have so far:</p> <pre><code> Bundle params = new Bundle(); params.putString("method", "photos.upload"); Toast.makeText(FacebookPoster.this, "" + getIntent().getExtras().getByteArray("data").length, Toast.LENGTH_SHORT).show(); params.putByteArray("picture", getIntent().getExtras().getByteArray("data")); AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook); mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null); </code></pre> <p>The Toast shows 8733, which means the byte array isn't empty</p> <p>NB. Logcat output some warnings (not errors):</p> <pre><code>03-02 14:19:29.554: WARN/Bundle(1891): Attempt to cast generated internal exception: 03-02 14:19:29.554: WARN/Bundle(1891): java.lang.ClassCastException: java.lang.String 03-02 14:19:29.554: WARN/Bundle(1891): at android.os.Bundle.getByteArray(Bundle.java:1305) 03-02 14:19:29.554: WARN/Bundle(1891): at com.facebook.android.Util.openUrl(Util.java:155) 03-02 14:19:29.554: WARN/Bundle(1891): at com.facebook.android.Facebook.request(Facebook.java:559) 03-02 14:19:29.554: WARN/Bundle(1891): at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253) 03-02 14:19:29.584: WARN/Bundle(1891): Key method expected byte[] but value was a java.lang.String. The default value &lt;null&gt; was returned. </code></pre> <p>(Shows several times underneath each other.)</p> <p><strong>What am I doing wrong?</strong></p> <hr> <p><strong>SOLVED.</strong> This is what I did to make it work:</p> <pre><code>facebook.authorize(this, new String[] { "publish_stream" }, new DialogListener() { @Override public void onFacebookError(FacebookError e) { // TODO Auto-generated method stub } @Override public void onError(DialogError dialogError) { // TODO Auto-generated method stub } @Override public void onComplete(Bundle values) { postToWall(values.getString(Facebook.TOKEN)); } @Override public void onCancel() { // TODO Auto-generated method stub } }); </code></pre> <p>And the helper method:</p> <pre><code>private void postToWall(String accessToken) { Bundle params = new Bundle(); params.putString(Facebook.TOKEN, accessToken); // The byte array is the data of a picture. params.putByteArray("picture", getIntent().getExtras().getByteArray("data")); try { facebook.request("me/photos", params, "POST"); } catch (FileNotFoundException fileNotFoundException) { makeToast(fileNotFoundException.getMessage()); } catch (MalformedURLException malformedURLException) { makeToast(malformedURLException.getMessage()); } catch (IOException ioException) { makeToast(ioException.getMessage()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload