Share dialog returns exception with “failed to gen

2019-07-18 19:24发布

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());

2条回答
淡お忘
2楼-- · 2019-07-18 20:05

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);
查看更多
萌系小妹纸
3楼-- · 2019-07-18 20:21

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());
查看更多
登录 后发表回答