robovm / robovm-robopods

63 stars 86 forks source link

Facebook OG Share not working correctly with pictures. #93

Open WillCalderwood opened 8 years ago

WillCalderwood commented 8 years ago

I'm not sure if this is going to be a RoboVM issue, but it seems a fairly major bug if Facebook let it slip through the net - that said, I know the picture is getting as far as the Facebook SDK as it previews correctly.

OG sharing appears to be working fine with the latest SDK, sharing both with and without pictures opens the ShareDialog as expected. If a picture is included it previews correctly in the displayed dialog. When clicking Post everything closes as expected, there are no errors logged and a little tick shows saying "Shared".

The problem is apparent when viewing on Facebook, there is no picture displayed. There is a box shown where you'd expect to see the picture, but there's nothing in it.

image

Here's some code based on Facebook samples that should work.

private void doSimpleShare(Pixmap pixmap) {
    ByteArrayOutputStream os = new ByteArrayOutputStream();

    // Convert the pixmap into a PNG as that's what we need for the Android bitmap object
    PixmapIO.PNG png = new PixmapIO.PNG();
    try {
        png.write(os, pixmap);
    } catch (IOException e) {
        e.printStackTrace();
        WordStormGame.getAnalytics().logException(e);
        WordStormGame.showErrorDialogThreadSafe(WordStormGame.getString("An_unexpected_error_occurred"));
        return;
    }

    NSData imageData = new NSData(os.toByteArray());
    UIImage image = new UIImage(imageData);

    FBSDKSharePhoto photo = new FBSDKSharePhoto();
    photo.setImage(image);
    photo.setUserGenerated(true);
    photo.setCaption("A Game of Thrones");

    FBSDKShareOpenGraphObject object = new FBSDKShareOpenGraphObject();
    object.putString("og:type", "books.book");
    object.putString("og:title", "A Game of Thrones");
    object.putString("og:description", "In the frozen wastes to the north of Winterfell, sinister and supernatural forces are mustering.");
    object.putString("books:isbn", "0-553-57340-3");
    object.putPhoto("og:image", photo);

    FBSDKShareOpenGraphAction action = new FBSDKShareOpenGraphAction();
    action.setActionType("books.reads");
    action.putObject("books:book", object);

    FBSDKShareOpenGraphContent content = new FBSDKShareOpenGraphContent();
    content.setPreviewPropertyName("books:book");
    content.setAction(action);

    FBSDKShareDialog dialog = new FBSDKShareDialog();
    dialog.setShareContent(content);
    dialog.show();
}