Working with the user profile

The BBM Social Platform provides both read and write access to a user’s BlackBerry Messenger profile. Your app can access their personal message, display name, status message, and display picture.

You can update the user's BBM profile by using the set functions in the bbmsp_userprofile API. A dialog displays to allow the user to accept or reject the change.

When a user or a contact makes a change to their BBM profile you can determine what was changed by retrieving the update type associated with the event that is triggered when the change is made. Use the event category and type to determine whether the change applies to a user or to a contact. Call bbmsp_event_profile_changed_get_presence_update_type() or bbmsp_event_contact_changed_get_presence_update_type() to retrieve the update type for a user or contact, respectively.

The following table summarizes the event categories and update types that relate to profile changes.

Event Update types
User profile:
  • category = BBMSP_USER_PROFILE
  • type = BBMSP_SP_EVENT_PROFILE_CHANGED
Contact list:
  • category = BBMSP_CONTACT_LIST
  • type = BBMSP_SP_EVENT_CONTACT_CHANGED

BBMSP_DISPLAY_NAME = 1

BBMSP_DISPLAY_PICTURE = 2

BBMSP_PERSONAL_MESSAGE = 4

BBMSP_STATUS = 8

BBMSP_INSTALL_APP = 16

BBMSP_UNINSTALL_APP = 32

Reading and writing to the BBM user profile

The following code samples show you how to read from and write to a user's BlackBerry Messenger profile. To access the user profile, you'll need to include the following classes in your app's header file.

#include "bbmsp/bbmsp_userprofile.h"
#include <bbmsp/bbmsp_presence.h>

Read a user's BBM profile

This code sample demonstrates how to read a user's BBM profile by retrieving their display name.

Begin by creating and initializing an empty profile object (m_profile), and then populating it with the user's BBM profile data.

// Initializes a pointer to the profile object
  bbmsp_profile_t *m_profile = 0;

// Creates the new, empty profile object
  bbmsp_profile_create(&m_profile);

// Populates the object with the user's profile data
  bbmsp_get_user_profile(m_profile); 

Next, define a function called read_profile_display_name() and pass in the user's profile data. Because you don't know the length of the user's display name, create an array (displayName) using the maximum allowed length to hold the string. Then call bbmsp_profile_get_display_name() and pass in the profile object, the array, and the array size. If the display name field is not empty, the string is returned in displayName and you print it out. Otherwise, print out an error message.

void read_profile_display_name(bbmsp_profile_t *m_profile)
{
    // Creates an array to hold the display name
    char displayName[BBMSP_PROFILE_DISPLAY_NAME_MAX];
    
    // Retrieves the display name, prompts the user to accept/reject,
    // and displays a message accordingly
    if(BBMSP_FAILURE == bbmsp_profile_get_display_name(m_profile, 
                         displayName,BBMSP_PROFILE_DISPLAY_NAME_MAX))
    {
      displayName[0] = 0;
      fprintf(stdout, "Error: Failed to get Display Name.\n");
    }
    fprintf(stdout, "BBMSP display name=%s\n", displayName);
}

Write to a user's BBM profile

Because BBM doesn't allow you to change a user's display name, the following code sample demonstrates how to write to a user's BBM profile by changing their personal message.

First, you define a function, write_profile_personal_message(). Then create an array (message) that contains the new message and pass it in to bbmsp_set_user_profile_personal_message(). The function displays a dialog box that shows the new personal message and prompts the user to accept or reject the change.

Screen showing the profile update confirmation dialog.

If the user accepts the change, bbmsp_set_user_profile_personal_message() writes the new message to the user's profile. Otherwise you print out a failure message.

Screen showing the updated user profile.
void write_profile_personal_message()
{
  // Creates an array with the new personal message
  char message[46] = "Updated by the BBMSP bps User Profile sample!";
  
  // Sets the personal message, prompts the user to accept/reject,
  // and displays a message accordingly
  if (BBMSP_FAILURE == bbmsp_set_user_profile_personal_message(message))
  {
    fprintf(stdout, "Failed to update personal message.\n");
  } else
  {
    fprintf(stdout, "Updated BBM SP personal message to:%s.\n",
                      message);
  }
}

You can download the complete sample app from the Core Native Community on GitHub.

Last modified: 2013-12-21

comments powered by Disqus