XMPP code examples

Expand
15 out of 18 rated this helpful - Rate this topic

XMPP code examples

We provide these code samples to demonstrate how to work with the Windows Live Messenger Extensible Messaging and Presence Protocol (XMPP) service from a client app for the Google Android mobile technology platform, and from a Java console-based client app.

Android XMPP client code sample

Download the Android XMPP client code sample.

We built our Android XMPP client code sample on the Android 2.3.3 platform with the asmack open-source XMPP library, version 2010.05.07.

Download the asmack library, version 2010.05.07.

This code sample uses our implementation of the OAuth implicit grant flow for getting an access token. You need an access token to sign in to the Messenger XMPP service. To get an access token, see the "Get an access token" section in Getting started using Messenger with XMPP. For details about our OAuth implicit grant flow, see OAuth 2.0.

This code sample highlights these features.

  • WLMActivity.java—This is the app's main class. This class gets the access token and maintains the UI. We hard-coded the sample client ID and redirect domain that we use to get the access token. You must change these two constants in the code to use your own client ID and redirect domain.

    public static final String OAuthAppClientId = "0000000048058C2E";
    public static final String OAuthAppRedirectUri = "http://xmpp.msgr-tst.com/desktop";
    
  • XmppClient.java—This is our XMPP client implementation that uses the asmack library. This class has all the logic for XMPP-specific operations like signing in to the Messenger XMPP service using an access token and handling XMPP stanzas.
  • XMessengerOAuth2.java—This class uses the asmack library to handle X-MESSENGER-OAUTH2 authentication.

Top

Java console-based XMPP client code sample

Download the Java console-based XMPP client code sample.

We built our Java console-based XMPP client code sample with JRE version 1.6 and the Smack open-source XMPP library, version 3.2.1.

Download the Smack library, version 3.2.1.

You must change the code to add your access token to sign in to the Messenger XMPP service. To get an access token, see the "Get an access token" section in Getting started using Messenger with XMPP.

This code sample highlights these features.

  • Program.java—This is the app's main entry point. You must change the TestAccessToken constant for this class to use your access token, like this.
    public static final String TestAccessToken = "ACCESS_TOKEN"
    
  • XmppClient.java—This is the XMPP client implementation that uses the Smack library. The class has all the logic for XMPP-specific operations like signing in to the Messenger XMPP service using an access token and handling XMPP stanzas.
  • XMessengerOAuth2.java—This class uses the Smack library to handle X-MESSENGER-OAUTH2 authentication.

Top

 

 

Build date: 4/26/2012

Did you find this helpful?
(1500 characters remaining)