Skip to content
This repository has been archived by the owner on Aug 3, 2019. It is now read-only.

Publish story

Roman Kushnarenko edited this page Oct 29, 2014 · 2 revisions

This doc is about to be udated till Dec 1st. All described below is great, but code supports much greater stuff (like dialog). Be updated.


It is possible to create and share open graph stories. Story consists of two main parts:

  • StoryObject - The object that you want to appear on the wall.
  • StoryAction - The action that relates to the object.

For example: Eat food is the definition for many possible food objects that can be eaten. Like:

  • Eat apple
  • Eat honey
  • Eat steak,
  • ...

So, what's now? Ok, these are the steps:

  1. Define new custom story in your app dashboard on facebook.
  2. Upload object meta tags that describe your noun (object) on your server or create one on facebook servers.
  3. Publish the story.

Example: Eat food

  1. Defined story:

    ± Create new object called: Food and add new custom property called calories of int type.
    ± Create new action called Eat and add new custom property called taste of string type.
    ± Edit the output of the story including the custom values.

  2. Upload object:

    Two options are possible:

    1. Use create(StoryObject, OnCreateStoryObject) - to create objects and upload them to facebook servers
    2. Upload story meta tags to your private servers.

    I used the option 2. Create these html page and upload to your server:

    <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# sromkuapp_vtwo: http://ogp.me/ns/fb/sromkuapp_vtwo#">
      <meta property="fb:app_id"               content="728615400528729" /> 
      <meta property="og:type"                 content="sromkuapp_vtwo:food" /> 
      <meta property="og:url"                  content="http://romkuapps.com/github/simple-facebook/object-apple.html" /> 
      <meta property="og:title"                content="Apple" /> 
      <meta property="og:image"                content="http://romkuapps.com/github/simple-facebook/apple.jpg" /> 
      <meta property="og:description"          content="The apple is the pomaceous fruit of the apple tree, Malus domestica of the rose family. It is one of the most widely cultivated tree fruits." /> 
      <meta property="sromkuapp_vtwo:calories" content="52" /> 

    I uploaded it to: http://romkuapps.com/github/simple-facebook/object-apple.html

  3. Publish the story:

    Initialize callback listener:

    OnPublishListener onPublishListener = new OnPublishListener() {
    	@Override
    	public void onComplete(String id) {
    		Log.i(TAG, "Published successfully. id = " + id);
    	}
    
    	/* 
    	 * You can override other methods here: 
    	 * onThinking(), onFail(String reason), onException(Throwable throwable)
    	 */
    };

    Build story for publishing:

    // set object to be shared
    StoryObject storyObject = new StoryObject.Builder()
    	.setUrl("http://romkuapps.com/github/simple-facebook/object-apple.html")
    	.setNoun("food")
    	.build();
    
    // set action to be done 
    StoryAction storyAction = new StoryAction.Builder()
    	.setAction("eat")
    	.addProperty("taste", "sweet")
    	.build();
    				
    // build story
    Story story = new Story.Builder()
    	.setObject(storyObject)
    	.setAction(storyAction)
    	.build();
    
    // publish
    mSimpleFacebook.publish(story, onPublishListener);

    The result:

Clone this wiki locally