Tuesday, May 8, 2012

How To Post Events into an OpenSocial Activity Stream

View Comments

Back at SXSWi 2012, I presented about Enterprise Social Media Trends and talked about OpenSocial and ActivityStrea.ms. OpenSocial was also a big topic at this year's Lotusphere 2012 conference. I've gotten probably about 10-15 requests on how to use these APIs in the last week, especially as a follow on to my post on How To develop Apps for IBM Connections so I thought it was time to create a blog entry for it.

As it turns out, yesterday Suzanne posted a great tutorial on how to get started with OpenSocial and Embedded Experiences.

I went through the tutorial and within 5 minutes I already had posted an event into the OpenSocial server with an embedded YouTube video as shown below. Very easy!:


The final step is to create a JSON object to push the event into the activity stream. I'm guessing that most of the people reading this are developers, so I'm going to use curl which works in most operating systems. I issue this command from the command line:

curl --user username:password
https://connections.swg.usma.ibm.com/connections/opensocial/basic/rest/activitystreams/@me/@all/@all
-X POST -L -H "Content-type: application/json"
--data-binary @youtube.json -i -v --insecure

And here's how the JSON object looks:

{ 
"generator": {
"image": { "url": "http://i2.ytimg.com/vi/Q5CU9cMvk7k/hqdefault.jpg"},
"id": "ytapp",
"displayName": "YouTube Application",
"url": "http://www.youtube.com/"
},
"actor": { "id": "@me" },
"verb": "post",
"title": "Video has been posted and is live !",
"content": " You have created a new YouTube video.",
"updated": "2012-05-08T12:00:00.000Z",
"object": {
"summary": "Video posted to YouTube",
"objectType": "note",
"id": "yt12",
"displayName": "YouTube Video",
"url": "http://public.dhe.ibm.com/software/dw/lotus/ee/video.xml",
},
"openSocial":{
"embed": {
"gadget": "http://public.dhe.ibm.com/software/dw/lotus/ee/video.xml",
"context": "Q5CU9cMvk7k"
}
}
}
And voilá. That's all it takes. Now go have fun!
blog comments powered by Disqus