Using the Jive Core API

Version 1

    Although Jive’s OpenSocial API support makes it easier for you to take an app written for another OpenSocial container and get it working in Jive communities, the Jive Core API gives more specific access to Jive community data. The Jive Core API is designed with Jive communities in mind, so accessing Jive community data with it is easier than with the OpenSocial API. You'll find that the Jive Core API is expressed in terms of concepts you're already familiar with in Jive, such as blog posts, Activity stream, and updates.

     

    Jive Core API provides access to data about content, people, places, and activity. As with the OpenSocial API, apps have access to the Jive Core API through JavaScript. For more on OpenSocial, be sure to see the Jive OpenSocial API tutorial and the Social Application tutorial.

     

    Here’s what you can access with Jive Core API, grouped according to categories:

    • People -- Avatar, Profile, Relationships, Search, User
    • Places -- Group, Project, Space
    • Content -- Blog, Blog Post, Category, Comment, Document, Like, Message, Update, Rate, Search, Tag, Thread
    • Activity -- Activity, Like, Mention, Recent Content

            Note: Jive Core supports the ability to retrieve activities only. You can write activities using the OpenSocial API and osapi.activities.create(). For more on this, see Jive OpenSocial tutorial.

     

    This tutorial helps you set up your app so it can take advantage of the features provided by the Jive Core API. The following steps help you get started.

    Step 1: Look at common Javascript requests

     

    In this step, we'll dissect a few sample apps so you can see how to use the Javascript API to make requests from Jive.

    Example: An app that posts to a blog

    Note: To execute this example, you must first create a personal blog in the sandbox. Please see the instructions HowTo create a personal blog for details on how to create your own blog.


    <?xml version="1.0" encoding="UTF-8"?>

    <Module>

      <ModulePrefs title="Post to blog">

        <Require feature="jive-core-v2" />

        <Require feature="dynamic-height" />

      </ModulePrefs>

      <Content type="html">

        <![CDATA[

          <script type="text/javascript">

            function getViewerBlog(callback) {

              osapi.jive.core.users.get({id: '@viewer'}).execute(function(userResponse) {

                if(!userResponse.error) {

                  var user = userResponse.data;

                  user.blog.get().execute(function(blogResponse) {

                    if(!blogResponse.error) {

                      var blog = blogResponse.data;

                      callback({viewerBlog: blog});

                    } else {

                      alert(blogResponse.error.message);

                    }

                  });

                }

              });

            }

            postBlogPost = function() {

                getViewerBlog(function(response) {

                  var blog = response.viewerBlog;

                  var subject = document.getElementById('blog_subject').value;

                  var html = document.getElementById('blog_content').value;

                  var blogEntry = {subject: subject, html: html};

                  var blogPostRequest = blog.posts.create(blogEntry);

                  blogPostRequest.execute(function(blogpostResponse) {

                    if(!blogpostResponse.error) {

                      alert("Yay! Posted.");

                    } else {

                      alert(blogpostResponse.error.message);

                    }

                  });

                });

                return false;

              };

            gadgets.util.registerOnLoadHandler(function() {

              getViewerBlog(function(response) {

                var blog = response.viewerBlog;

                var blogName = document.getElementById('blog_name');

                blogName.innerHTML = 'Blog: ' + blog.name

              });

            });

          </script>

          <form id="blogpost_form" onsubmit="return postBlogPost();">

            <p>

              <div id="blog_name"></div><br />

              <label for="blog_subject">Subject:</label><input id="blog_subject" /><br />

              <label for="blog_content">Content:</label><input id="blog_content" /><br />

              <input type="submit" value="Post">

            </p>

          </form>

        ]]>

      </Content>

    </Module>

                  

    Code
    Function
    <Require feature="jive-core-v2" />

    Leverages classes from the Jive Core API by requiring it as a feature in this app.

     

    The Jive Core API leverages jQuery.

    osapi.jive.core.users.get({id: '@viewer'}).execute(function(userResponse) {Uses the Jive Core Users class to get the app user.
    user.blog.get().execute(function(blogResponse) {Uses the Jive Core Blog class to get the app user's blog.
    var blogPostRequest = blog.posts.create(blogEntry);Uses the Jive Core Blog class to create a blog post in the user's blog.

     

    Example: An app that posts a status update


    <?xml version="1.0" encoding="UTF-8" ?>

    <Module>

      <ModulePrefs title="Jive Core Example: Updates">

        <Require feature="jive-core-v2" />

        <Require feature="dynamic-height"/>

      </ModulePrefs>

      <Content type="html">

        <![CDATA[

          <script type="text/javascript">

           function loadUpdates() {

              osapi.jive.core.updates.get({limit: 10}).execute(function(response) {

                if(!response.error) {

                  var updates = response.data;

                  var recentUpdates = document.getElementById('recent_updates');

                  while(recentUpdates.hasChildNodes()) {

                    recentUpdates.removeChild(recentUpdates.lastChild);

                  }

     

                  for(i = 0; i < updates.length; i++) {

                    var update = updates[i];

                    var user = update.author;

                    var node = document.createElement('li');

                    node.innerHTML = "<strong>" +  (user ? user.name + ": " : "") + "</strong>" +

                      update.content.text;

                    recentUpdates.appendChild(node);

                  };

                  gadgets.window.adjustHeight();

                };

              });

            };

     

            postUpdate = function() {

                var html = document.getElementById('update_entry').value;

                osapi.jive.core.updates.create({userId: '@viewer', update: {html: html}}).

                  execute(function(response) {

                  if(!response.error) {

                    var updateEntry = document.getElementById('update_entry');

                    updateEntry.value = '';

                    loadUpdates();

                  }

                });

                return false;

              };

            gadgets.util.registerOnLoadHandler(loadUpdates);

          </script>

          <style>

          body {

            font-family: "Lucida Grande", Helvetica, Arial, sans-serif;

          }

          #update_form {

            margin: 5px;

            background: #f6f6f6;

            border: 1px solid #ccc;

            padding: 3px;

          }

          #update_form p {

            margin: 0;

          }

          #update_entry {

            width: 95%;

            border: 1px solid #ccc;

            font-size: 12px;

            line-height: 18px;

            padding: 3px;

          }

     

          #updates {

            margin: 5px;

            padding: 3px;

            overflow: auto;

          }

          #updates h3 {

            margin: 0 0 5px 0;

            border-bottom: 1px solid #ccc;

            font-weight: normal;

          }

     

          #recent_updates {

            list-style: none;

            margin: 0;

            padding: 0;

          }

          #recent_updates li {

            border-bottom: 1px solid #ccc;

            font-size: 11px;

            padding: 6px 0;

          }

          </style>

          <!-- Form to create an update -->

          <form id="update_form" onsubmit="return postUpdate();">

            <p>

              <label for="update_entry">What's going on?</label><br />

              <input id="update_entry" />

              <input type="submit" value="Go">

            </p>

          </form>

          <!-- Display recent updates -->

          <div id="updates">

            <h3>Most Recent Updates</h3>

            <ul id="recent_updates"></ul>

          </div>

        ]]>

      </Content>

    </Module>

     

    CodeFunction
    <Require feature="jive-core-v2" />Leverages classes from the Jive Core API by requiring it as a feature in this app
    <Require feature="dynamic-height"/>Standard OpenSocial feature for dynamically adjusting the height of a rendered  application
    osapi.jive.core.updates.get({limit: 10}).execute(function(response) {Uses the Jive Core Update class to get the last 10 updates
    osapi.jive.core.updates.create({userId: '@viewer', update: {html: $('#update_entry').val()}}).Uses the Jive Core Update class to create an update

     

    Step 2: Identify Jive Core Available Features

     

    The classes and namespaces in Jive use the following nomenclature:

    • Lowercase/plural namespaces provide static methods for getting objects from Jive.
    • Singular/lowercase represents the class that provides update/delete create functions.


    You can use the following references to identify Jive Core features. The JavaScript API uses JavaScript to access the REST API so you don't have to. For server to server integration, Jive provides a REST API.

     

     


    << PreviousNext >>
    Using the OpenSocial APIUsing the Jive Application Gateway API