5

I'm getting a UnknownHostException when trying to post a photo to the user wall. Here is my code:

    byte[] data = null;

    Bitmap bi = BitmapFactory.decodeResource(getResources(), aDrawableId);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bi.compress(Bitmap.CompressFormat.JPEG, 70, baos);
    data = baos.toByteArray();

    Bundle parameters = new Bundle();
    parameters.putByteArray("picture", data);
    Log.i(getClass().toString(), parameters.toString());

    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(this.facebook);
    String method = String.format("me/photos?access_token=%s", this.facebook.getAccessToken());
    mAsyncRunner.request(method, parameters, "POST", new FacebookRequestListener(), null);

The permissions on my AndroidManifest file:

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

I had the same problem as the following question before and I correct using the second answer (the top voted one):

Post message to facebook wall from android fb sdk always error

The only message I get in logcat is:

10-26 15:29:16.425: E/Facebook(5342): java.net.UnknownHostException: graph.facebook.com

Do you guys have any ideas on how to solve this? I'm running the app on a stock Galaxy S2 device.

Community
  • 1
  • 1
renam.antunes
  • 761
  • 1
  • 5
  • 11

1 Answers1

1

I'm not sure if this will fix the error you get, but a few things I noticed:

The documentation (under the Photos connection) states the the picture parameter is named source (and not picture as you used).

The facebook sdk adds the access token to the api requests, so you don't need to do that (you can look at the source. I don't think that it should be a problem for POST requests, but if you use GET then the sdk adds "?" to the path, and in your case you'll end up with two of those.

Have you managed to find the problem?

Nitzan Tomer
  • 155,636
  • 47
  • 315
  • 299
  • I got it working, somehow. I updated my facebook library and rewrote the code until something worked. To this day I'm not sure what did it. But thanks for the answer. – renam.antunes Mar 06 '12 at 13:15
  • @renam.antunes updating to latest Facebook.apk fixed it for me too – bgs Apr 30 '12 at 01:22