Creating an App Activity
Now that we have the login and logout working, let’s finish the app and give the user a way to state that they want the listed car (see Figure 5).
To create the WantActivity, we should markup the wanted item with microdata. HTML5 Microdata is a means to semantically specify structured objects in a web page. The Google API uses the items tagged with microdata to retrieve information about the item like the image, name, or description.
<a name="RedMini"></a> <div itemscope itemtype="http://schema.org/Product" class="row"> <img itemprop="image" class="offset3 span5" src="images/car/red-mini.jpg"/> </div> <div class="row offset4"> <span itemprop="name">Red Mini</span>-<span itemprop="description">2010(?) Mini Cooper</span> </div>
To create the WantActivity, we again create a client API request, this time passing along a JSON object specifying the type of activity and the required attributes for that type. We can see that in the following function:
function makeWantActivity() { // Address must be publicly accessible var root = ‘http://0.0.0.0:5050/index.html’ var body = { ‘type’:‘http://schemas.google.com/WantActivity’, ‘target’: { ‘url’:root+‘#RedMini’ }, }; var request = gapi.client.request ({ path:‘/plus/v1/people/me/moments/vault’, method:‘POST’, debug: true, body:body }); var callback = function (result) { console.log(result); alert("WantActivity posted to your Google+ profile.") }; request.execute(callback); }
The activity will now show on our profile page with the privacy level we set when logging in. It could be viewable to just you, all of your circles, or a subset of them (see Figure 6).
From this area, we can also share the activity to the Google+ stream (see Figure 7).