Orkut Application Platform

The orkut Client Library - Profile Requests

Bruno Oliveira - Developer Relations
December 2010

This section of the guide explains how to perform common profile 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.


Requesting a Profile

In its simplest form, reading a profile is just a matter of submitting a GetProfileTx transaction, for example:

BatchTransaction btx = orkad.newBatch();
GetProfileTx profile = orkad.getProfileTF().getSelfProfile();

OrkutPerson person = profile.getProfile();
System.out.println("Hello, " + person.getGivenName());

OrkutPerson is the class that represents an orkut profile in the library. However, you will notice that OrkutPerson has several interesting fields, and most of them are returned as 0 or null by default.

This is because, in order to save on bandwidth, orkut only reports the profile fields which you explicitly ask for. In order to ask for a profile field, you have to call the appropriate method in the GetProfileTx object indicating your interest in the field.

For example, if you want the returned profile to come with the URL for the person's thumbnail photo, then you must call alsoGetThumbnailUrl() on the profile transaction object. Naturally, you must do so before submitting it to the server.

Here are the functions that you can call on your GetProfileTx to request different parts of the profile:

  • alsoGetName()
  • alsoGetThumbnailUrl()
  • alsoGetProfileUrl()
  • alsoGetStatus()
  • alsoGetEmails()
  • alsoGetGender()
  • alsoGetPhoneNumbers()
  • alsoGetBirthday()
  • alsoGetAddress()

Here is a code snippet that reads and prints all of the available profile information (the nullsafe() function is shown right after the code):

BatchTransaction btx = orkad.newBatch();
GetProfileTx profile = orkad.getProfileTF().getSelfProfile();

say("Getting self profile (extended)...");

OrkutPerson person = profile.getProfile();
if (persion == null) {
   say("No profile info returned.");

say("ID                    : " + nullsafe(person.getId()));
say("Given name            : " + nullsafe(person.getGivenName()));
say("Family name           : " + nullsafe(person.getFamilyName()));
say("Display name          : " + nullsafe(person.getDisplayName()));
say("Thumbnail URL         : " + nullsafe(person.getThumbnailUrl()));
say("Status                : " + nullsafe(person.getStatus()));
say("Gender                : " + nullsafe(person.getGender()));
say("Profile URL           : " + nullsafe(person.getProfileUrl()));
say("Birthday (long)       : " + String.valueOf(person.getBirthday()));

com.google.orkut.client.api.Address address = person.getAddress();
if (address != null) {
   say("Address               : ");
   say("       Country code   : " + nullsafe(address.getCountryCode()));
   say("       Region code    : " + nullsafe(address.getRegion()));
   say("       Locality       : " + nullsafe(address.getLocality()));
   say("       Postal Code    : " + nullsafe(address.getPostalCode()));
   say("Address                  : [not returned]");

int count = person.getEmailCount();
int i;
say("E-Mails: (" + String.valueOf(count) + ")");
for (i = 0; i < count; i++) say("  - " + nullsafe(person.getEmail(i)));

count = person.getPhoneNumberCount();
say("Phones: (" + String.valueOf(count) + ")");
for (i = 0; i < count; i++)
   say("  - " + nullsafe(person.getPhoneNumber(i)));

What if you wanted to read not your own profile, but that of a friend? In that case, it's just a matter of issuing a different transaction. Instead of calling getSelfProfile() on the factory, call instead getProfileOf() and pass it the ID of the profile you wish to query:

GetProfileTx profile = orkad.getProfileTF().getProfileOf(id);

Notice that not all data will be returned for all queries, especially for friends, depending on privacy settings. Therefore, always be prepared to receive a null return value from any method query. That's why we're checking each return value for null before using the value. In our example this is done by the very simple nullsafe function, shown below:

private static String nullsafe(String s) { return s == null ? "null" : s; }

Updating Status

You can easily update the user's status (which also generates an update on his newsfeed). Doing this is very straightforward using a UpdateProfileTx:

String newStatus = "Learning the orkut Client Library!";
UpdateProfileTx tx = orkad.getProfileTF().updateSelfProfile();

BatchTransaction btx = orkad.newBatch();

Fetching Birthday Notifications

In order to fetch birthday notifications for the user, you can simply use the BirthdayNotificationTx transaction as illustrated below. It will return a list of all active birthday notifications, with profiles, ID's and birthdates.

BirthdayNotificationTx tx =
BatchTransaction btx = orkad.newBatch();

if (tx.hasError()) {
    // handle error
    say("Error fetching birthday notifications.");

for (int i = 0; i < tx.getBirthdayNotificationCount(); ++i) {
   BirthdayNotificationEntry entry = tx.getBirthdayNotification(i);
   say("User: " + entry.getUserProfile().getDisplayName() +
        " (" + entry.getUserId() + ") Birthdate: " +
        entry.getBirthDay() + "/" + entry.getBirthMonth());

Fetching Friend Invite Notifications

Similarly, you can get friend invite notifications by using a PendingFriendRequestTx:

PendingFriendRequestTx tx = 
BatchTransaction btx = orkad.newBatch();

if (tx.hasError()) {
   // handle error

for (int i = 0; i < tx.getPendingFriendRequestCount(); ++i) { 
   FriendRequestEntry entry = tx.getPendingFriendRequest(i);
   say("User: " + entry.getUserProfile().getDisplayName() +
       " (" + entry.getUserId() + ") " +
       "Message: " + entry.getMessage());

Authentication required

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

Signing you in...

Google Developers needs your permission to do that.