问题
I am developing a game app. And I am sharing facebook custom stories in my app.I have created a self hosted object(html page).
I want to use that same self hosted object in android,ios and Facebook canvas app. I have already done custom story sharing without using self hosted object for android app and below is my code for the same
OpenGraphObject objProperty = OpenGraphObject.Factory.createForPost("namespace:level");
objProperty.setProperty("title","Title");
objProperty.setProperty("image","http://www.example.com/jokedemo/image/wrong.jpg");
objProperty.setProperty("url", "http://www.example.com");
objProperty.setProperty("description", "Can you beat me?");
OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
action.setProperty("level", objProperty);
FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(FBActivity.this, action,"namespace:unlock", "level").build();
where unlock
is my action and level
is my object.
But I want it to do using self hosted object that I have created so that I can use same object for all platforms (Android, IOS , Web).
In documentation it is mentioned that Self-Hosted Objects are more useful for multi platform app than using Object api. I followed this https://developers.facebook.com/docs/opengraph/using-objects/#selfhosted document but couldn't found anywhere there how to use it on Android.
My code for creating an self hosted object (html page)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta property="fb:app_id" content="*************" />
<meta property="og:type" content="namespace:level" />
<meta property="og:title" content="Title" />
<meta property="og:url" content="https://example.com/namespace/level.html" />
<meta property="og:description" content="Can you beat me?" />
<meta property="og:image" content="https://example.com/namespace/image/abc.png" />
</head>
<body>
</body>
</html>
If I want to use self hosted object in my Android what will be the changes in my working code or I have to do it in another way ?
Any suggestion will be highly appreciated, Thank you in advance.
回答1:
Finally I solved it , actually method was there in the document itself , but it wasn't specifically mentioned there that this code will be used for self hosted object.
Below is my code :
OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
action.setProperty("level","https://example.com/namespace/level.html"); //here "level" is the Object name and url is the self hosted object
action.setType("namespace:unlock"); //"unlock" is the Action name
FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(FBActivity.this, action, "level").build();
回答2:
There is an example of using a URL (self hosted object) in the FB docs. Although they now refer to it as an app owned object. Just about to test it.
https://developers.facebook.com/docs/ios/ui-controls#share-appownedobjects
来源:https://stackoverflow.com/questions/23995978/how-to-create-and-use-self-hosted-objects-to-share-custom-stories-in-android