Question

I am trying to share an image via the android facebook API to facebook. Sharing text and links works fine, uploading an image, too. I found out, that I only can post images, if they are online or in the photoalbum of the user.

Bundle bundle = new Bundle();
    bundle.putParcelable("picture", b);

    Request request = new Request(session, "me/photos", bundle,
            HttpMethod.POST, new Request.Callback() {
                @Override
                public void onCompleted(Response response) {
                    String imageid = (String) response.getGraphObject()
                            .getProperty("id");
                    share(session, text, imageid);
                }
            });

    RequestAsyncTask task = new RequestAsyncTask(request);
    task.execute();

imageid is a number like "123456789908765345678"

After the execution, "share" is called:

    Bundle bundle = new Bundle();
    bundle.putString("caption", "some text");
bundle.putString("description", "Imageid:"+imageid);
    bundle.putString("link",
        "https://link.de");
    bundle.putString("name", "some text");
    bundle.putString("place", imageid); //It doesn't work for me

     new WebDialog.FeedDialogBuilder(this, session,      bundle).build().show();

I don't know what I am doing wrong. I simply want so share this image.

Help please :)

Was it helpful?

Solution

You have to make another request with the id of the resource in order to get the url of the image you are trying to reference in the share dialog.

So you should do something like this:

Callback callback = new Callback() {

   @Override     
   public void onCompleted(Response response) {

     if (response.getGraphObject() != null) {
        String imageUrl = (String) response.getGraphObject().getProperty("picture");
        // call to your sharing method
    share(session, text, imageUrl);                             
      }
    }
 };


Request request = new Request(Session.getActiveSession(), imageid, null, HttpMethod.GET,     callback);
request.executeAsync();

OTHER TIPS

You can upload the photo to facebook album using

com.facebook.Request fbRequest = com.facebook.Request.newUploadPhotoRequest(session, image, callback);
fbRequest.executeAsync();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top