Share dialog returns exception with “failed to gen

2019-07-18 19:31发布

问题:

I have switched to use the newly updated Facebook SDK for Android.

The above message was given in an FacebookException class when I tried to use the new Share Dialog.

Any reason why this happens?

Here's the code I'm using.

OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
            action.setProperty("object", "http://object.url");

FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(this, action, "appnamespace.action", "object")
                    .build();
uiHelper.trackPendingDialogCall(shareDialog.present());

回答1:

After hours and hours of trial and error, I've finally figured this out. Wish it was much simpler though. Facebook should provide a code generator.

Anyways, the solution for my problem is that the action word has to match the one that facebook set perfectly. The only way to see this is at the open graph code generator for types.

https://developers.facebook.com/apps/{app-id}/opengraph/types

You can find it at the above link at the action types section.

Now, take the namespace and action type that facebook provided and replace it with "appnamespace:action" below.

OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
        action.setProperty("object", "http://object.url");

FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(this, action, "appnamespace.action", "object")
                .build();
uiHelper.trackPendingDialogCall(shareDialog.present());


回答2:

I believe the issue is related to the "previewPropertyName" field int he OpenGraphActionDialogBuilder constructor.

new FacebookDialog.OpenGraphActionDialogBuilder(Activity activity, OpenGraphAction action, String previewPropertyName)

This must match the name of the property in the action that points to the OpenGraphObject itself. example

action.setProperty("previewPropertyName", openGraphObject);