Working with User Data

Current information about Live Connect is now available in the Windows Live Developer Center. The information in the following sections is provided for legacy purposes only.

Each user in a Messenger Connect application is represented by an object of class User. This object allows you to sign in and sign out the user, track presence and active conversations, and display user data.

This topic describes the most common tasks that are typically performed with a User object.

Before you can get the User object that corresponds to a particular user, you must ensure that the user's scope will allow sign in. To allow a user to sign in, you must extend a Messenger.SignIn offer in the scope specified by the <wl:app> tag. For more information about the <wl:app> tag and Messenger scopes, see Application Control.

The following example shows an Application control that extends the Messenger.SignIn offer.


For more information about Messenger Connect scopes, see Messenger Connect Scopes.

Once you've ensured that the user has the correct scope, the user is able to sign in using Messenger Context. For more information about Messenger Context, see Using the Messenger Context.

The following example demonstrates how to get the messenger context and use it to sign in the user.

messengerContext = wl.App.get_messengerContext();
var status =;
messengerContext.signIn(status, onSignedIn);

Once the user is signed in, you can get the User object and with it get user data.

user = messengerContext.get_user();

When you instantiate a User object, you should create an event handler that detects when the object becomes available. There can be a small delay between the time when you create a User object and the time when you can begin accessing its members.

The following procedure demonstrates the recommended method for accessing a User object:

  1. Define an onPropertyChanged handler for the MessengerContext object. The handler can detect when a user logs in.
    messengerContext = wl.App.get_messengerContext();
  2. In the onPropertyChanged handler, determine whether the changed property is messengerContext.user, and whether the user has just signed in. If the user property has been changed and the user has signed in, the user object is now available.
    function onPropertyChanged(sender, args)
        if(args.get_propertyName() == "user") 
           user = messengerContext.get_user();
            If (user.status == Microsoft.Live.Messenger.UserStatus.signedIn)
                alert("The user object is available");

Each Windows Live Messenger Connect user has a list of contacts with whom that user can converse. You can modify a user's contacts by using an Add Contact Control UI control, or by working with the user's contact list programmatically as outlined in the following steps:

  1. Get the ContactCollection instance for the current user.
    messengerContext = wl.App.get_messengerContext();
    user = messengerContext.get_user();
    contactCollection = user.get_contacts();
  2. Subscribe to the AddContactCompletedEventHandler handler.
  3. Add a contact to the contact list.
    var address = "";
    user.addContact(address, 'Invitation message.', null);
  4. Remove a contact from the contact list.
    var address = "";
    var contact = contactCollection.find(address, Microsoft.Live.Messenger.IMAddressType.windowsLive);

For more information about adding contacts to a user's contact list, see Adding and Removing Contacts (JavaScript Library).

You can manage user conversations with the Conversation Control, or the User class. For more information about managing user conversations, see Managing Conversations.