Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
624 views
in Technique[技术] by (71.8m points)

facebook - How to create and use self hosted objects to share custom stories in Android?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...