Orkut Application Platform

The orkut Client Library - Activity Requests

Bruno Oliveira - Developer Relations
December 2010

This section of the guide explains how to perform common activity operations using the orkut Client Library. If you haven't read it yet, please read the Introduction to the Client Library first, since we'll assume you know how to perform the library and environment setup.

Contents:

What's an Activity?

Each of the items that appears in the "updates" feed is an activity. There are several types of activity that represent different types of updates, such as for example profile updates, status message updates, photo posting, photo comments, etc. One particular type of activity are activities posted by applications -- these are known to developers as "makamaka" activities.

Posting Activities

Posting a new activity is easily accomplished by using a PostActivityTx:

PostActivityTx tx = orkad.getActivityTF().postActivity(title,body);
BatchTransaction btx = orkad.newBatch();
btx.add(tx);
orkad.submitBatch(btx);

if (tx.hasError()) say("*** Error posting activity.");
else say("Success!");

Notice that you have to provide a title and a body for your activity. The body may include some limited HTML markup, but you should try to keep it simple.

Also, please mind the Developer Guidelines when posting updates. For example, using bigger fonts or animated GIF's is currently not allowed.

Fetching the Activity Stream

Fetching the user's activity stream (which is essentially what he sees in his "updates" feed) can be accomplished by means of the GetActivitiesTx transaction.

After issuing that transaction, you will be given the first few activities (the current default is 10) which you can query with getActivityCount() and getActivity(i). The transaction has a method called hasNext() that allows you to query as to whether there are more updates to load or not. If you wish to load more updates (assuming, naturally, that hasNext() has returned true), you can issue a new transaction generated from the factory through the current transaction, and the new transaction will result in the next few activity entries. This is better illustrated with code, so let's look at a code snippet that prints the user's activity stream until the user says it's enough.

BatchTransaction btx = orkad.newBatch();
GetActivitiesTx activities = orkad.getActivityTF().getSelfActivities();
btx.add(activities);

say("Getting activities...");
orkad.submitBatch(btx);

int page = 0;
while (true) {
   say("Page: " + String.valueOf(++page));
   for (int i = 0; i < activities.getActivityCount(); i++) {
      ActivityEntry entry = activities.getActivity(i);
      say(entry.toString());
   }

   if (!activities.hasNext()) break;
   say("Get next page [y/n]? ");
   if (!readline().toLowerCase().startsWith("y")) break;

   activities = orkad.getActivityTF().getNext(activities);
   btx = orkad.newBatch();
   btx.add(activities);
   orkad.submitBatch(btx);
}

Observe how we get a new transaction from the existing one by calling getNext() on the ActivityTxFactory provided by our OrkutAdapter.

If you want to control how many activities will be returned in each "page", you can call the setCount() method on the transaction.

activities.setCount(20);  // get 20 activities per page

What if you wanted to read someone else's activity stream, as opposed to your own? In this case, it's a simple matter of replacing getSelfActivities() by getActivitiesOf():

BatchTransaction btx = orkad.newBatch();
GetActivitiesTx activities = orkad.getActivityTF().getActivitiesOf(id);
btx.add(activities);

Activity Types

Our sample code above simply prints an ugly string version of each activity entry. That string conversion is not meant for production, only for debugging, so it doesn't really include very friendly information. Instead of showing activities that way, your application will probably want to format them more appropriately according to the activity type.

Giving a detailed explanation about each activity type is not in the scope of this quick guide, but here is a list of the classes (all subclasses of ActivityEntry) that represent the different types of activity that you may get:

  • FriendAddActivity
  • GenericActivity
  • MakamakaActivity
  • PhotoCommentActivity
  • PhotoShareActivity
  • ProfileUpdateActivity
  • ScrapActivity
  • SocialEventActivity
  • StatusMessageActivity
  • TestimonialActivity
  • VideoShareActivity

If displaying the activity stream is an important feature of your application, you should consider looking into each of these classes and deciding which ones you want to support and consider how to display them most effectively in your application.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.