Nick's .NET Travels

Continually looking for the yellow brick road so I can catch me a wizard....

Windows Phone 7 Beta with Windows Live Messenger Connect

Recent Microsoft announced a major update to their Live platform. There are a number of updates that are currently in Beta including Messenger and Live Writer but what interests me is the new development platform, Messenger Connect. Go to the Windows Live developer portal for all the details. For anyone who has worked with any of the Live Id apis in the past it was difficult to get all the information you wanted. It appears that Messenger Connect is a great rationalisation of these apis and with libraries to support both rich and web client access, getting started should be easy.

Unfortunately, and for those getting into the Windows Phone space you’ll get used to this, there is no library available for accessing the Messenger Connect apis. Of course, the team has done a great job of making all the data available via REST  but honestly, that’s like trying to write a Windows Phone app in XAML when you have the power of Blend…. not something you want to have to do.

I figured it couldn’t be that hard to take the existing library for Silverlight, decompile it thanks to Reflector, update it to work for Windows Phone and we should be good to go. No so, after quite a painful day yesterday I have got a working library that’s able to authenticate and access contacts and activities (haven’t tested the other functionality yet). Unfortunately this meant not only reverse engineering the Microsoft.Live.dll but also the odata sdk library for Windows Phone (as they haven’t made the source available). Anyhow, enough complaining about the lack of source code publishing by Microsoft (please, please, please Microsoft, stop closed-sourcing these sdk libraries – all it does is frustrate us!).

So the SDK library is relatively easy to use:

- Start by adding a reference to the Microsoft.Live and System.Data.Services.Client (the one in the attached zip file, not the odata sdk version).

- Next, you’ll need a WebBrowser control on the page that you’re going to do the authentication on – this is used to display the Messenger Connect sign in prompt. The SDK library for Silverlight uses a ChildWindow but this isn’t available for Windows Phone so I’ve hacked around this for the moment. I’m sure there’s a better solution for this so feel free to modify it

- Add a button and some code to authenticate the user:

const string ClientId = "***Your-Client-ID***";
const string ClientSecret = "***Your-Secret-Key***";

LiveDataContext dataContext = new LiveDataContext();
AppInformation appInfo;

private void SignInButton_Click(object sender, RoutedEventArgs e)
{
    SignInButton.IsEnabled = false;

    try
    {
        appInfo = new AppInformation(ClientId, ClientSecret);
        appInfo.RequestedOffers.Add(new Offer()
        {
            Name = "WL_Contacts",
            Action="View"
        });
        appInfo.RequestedOffers.Add(new Offer()
        {
            Name = "WL_Activities",
            Action = "View"
        });
        appInfo.RequestedOffers.Add(new Offer()
        {
            Name = "WL_Photos",
            Action = "View"
        });
                
        this.dataContext.SignInAsync(this.SignInBrowser, appInfo, null);
    }
    catch (Exception ex)
    {
        ShowErrorDialog("Failed to sign in to Windows Live: {0}", ex.Message);
        SignInButton.IsEnabled = true;
    }
}

private void SignInCompleted(object sender, SignInCompletedEventArgs e)
{
    if (!e.Succeeded)
    {
        string authError = (e.AuthInfo.Error == null) ? string.Empty : e.AuthInfo.Error.Message;
        ShowErrorDialog("Failed to sign in to Windows Live! {0}", authError);
        SignInButton.IsEnabled = true;
    }
    else
    {
        MessageBox.Show("Welcome To Windows Live!", "Windows Live", MessageBoxButton.OK);
        this.Contacts.Visibility = System.Windows.Visibility.Visible;
    }
}

private static void ShowErrorDialog(string errMsg, params string[] paras)
{
    MessageBox.Show(string.Format(errMsg, paras), "Windows Live", MessageBoxButton.OK);
}

Essentially the process goes like this:

- the user clicks the SignInButton
- the WebBrowser control is displayed and navigates to the Messenger Connect sign in page
- the user signs in and grants appropriate privileges
- after sign in the WebBrowser is automatically hidden and the SignInCompleted event is raised

In action:

image

In the code to sign in you will have noticed that there are three Offers that have been requested. These correlate to the scopes of information that the user is going to grant this application. In this case View privileges to Contacts, Photos and Activities. To retrieve these sets of information we can kick of an odata service call.

private void FetchContactsButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
    var qry= dataContext.ContactsQuery;
    qry.BeginExecute(Response, qry);
}
void Response(IAsyncResult result)
{
    var qry = result.AsyncState as DataServiceQuery<Contact>;
    var contacts = qry.EndExecute(result);
    this.Dispatcher.BeginInvoke(() =>
    {
        this.InformationList.Items.Clear();
        foreach (Contact c in contacts)
        {
            this.InformationList.Items.Add(c.ToString());
        }
    });
}

private void FetchActivitiesButton_Click(object sender, RoutedEventArgs e)
{
    var qry = dataContext.MyActivitiesQuery;
    qry.BeginExecute(ActivitiesResponse, qry);
}

void ActivitiesResponse(IAsyncResult result)
{
    var qry = result.AsyncState as DataServiceQuery<Activity>;
    var contacts = qry.EndExecute(result);
    this.Dispatcher.BeginInvoke(() =>
    {
        this.InformationList.Items.Clear();
        foreach (Activity c in contacts)
        {
            this.InformationList.Items.Add(c.ToString());
        }
    });
}

This code illustrates retrieving the list of contacts and activities for the currently signed in user.

Hopefully this will help you build a Windows Phone application that takes advantage of the new Messenger Connect apis. Oh, before I forget, to get the sample to work you’ll need to sign up for access to the Messenger Connect apis, then register your application (use the Windows Application option). Include the ClientId and ClientSecret at the top of the MainPage.xaml.cs (first code sample above).

Messenger Connect Sample: Download Sample

Update: It’s important that you read the licensing agreements that accompany the use of the apis. Angus posted on Messenger Connect saying the following:

    1. Public APIs: Our “Public APIs” are available to all developers and third parties to access in a self-service manner. Appropriate use is governed by our Terms of Use and Terms of Service, and is monitored for abuse reported by customers. Third parties can sign-up for access through our application management tool at http://manage.dev.live.com.

Comments (9) -

  • Dimaz Pramudya

    26/07/2010 6:24:57 PM |

    Hi Nick,

    Is there anyway to do the Authentication process without showing the WebBrowser control?
    Would love to see something similar to xAuth.

    //D

  • nick

    26/07/2010 6:41:22 PM |

    Dimaz, no there isn't for the same reason as there wasn't for the old Live Id Web Authentication. This process is aweful and not really designed for rich client apps but seems to be the way of the future for web authentication systems (Twitter and Facebook both use a similar approach from what I know).

  • Trees

    26/07/2010 9:42:24 PM |

    Hey Nick, Looks like you were having some fun there :).. wouldn't it be interesting if a similar approach opened the door to contact info in Outlook on the phone. There's quite a bit of demand for this. I'm guessing though that Outlook won't be storing any data here.. have you heard anything in your travels?

  • Trees

    26/07/2010 9:42:50 PM |

    Hey Nick, Looks like you were having some fun there :).. wouldn't it be interesting if a similar approach opened the door to contact info in Outlook on the phone. There's quite a bit of demand for this. I'm guessing though that Outlook won't be storing any data here.. have you heard anything in your travels?

  • Trees

    26/07/2010 9:43:57 PM |

    Hey Nick, Looks like you were having some fun there :).. wouldn't it be interesting if a similar approach opened the door to contact info in Outlook on the phone. There's quite a bit of demand for this. I'm guessing though that Outlook won't be storing any data here.. have you heard anything in your travels?

    ps: cast error posting comments from firefox, had to load ie.

  • Trees

    26/07/2010 9:44:51 PM |

    soz, delete repeats - thought failure was not posting comment - same error in ie btw.

  • Paul Griffiths

    28/07/2010 1:03:15 PM |

    looks nice nick, but there's no chance such an app would get certified.  the terms and conditions of Messenger only allow to use it in certain ways for PCs and for mobiles.   there are many apps that hack messenger (e.g. ebuddy) and they get away with it on non-microsoft platforms like the iphone.      but there's a reason why the only messenger for winmo6 is the official microsoft one...... they just won't certify any 'rogue' developer using the api.

    just giving you heads up so you don't waste too much efforts and get disappointed!!!!   can you hack maybe an ICQ or Y! Messenger app?  i'd love to see that!!

  • nick

    28/07/2010 3:53:42 PM |

    Paul, Don't be confused about "Messenger" (as in Live Messenger) and "Messenger Connect" (as in Live Id Auth apis). At the end of the day all I'm accessing are the public apis.

  • Dissertation Help

    29/10/2010 5:32:30 AM |

    Wonderful post about "Windows Phone 7 Beta with Windows Live Messenger Connect".

  • viagra generico

    5/01/2011 10:19:32 AM |

    Your site offers a lot of unique insights and information. I have
    neverreally thought about it like that. Please keep updating your
    homepage.
    I will be stopping over every time you do .

  • Capodanno roma

    15/02/2011 3:48:08 AM |

    First of all, I would like to appreciate the effort that you have put in making such an informative blog. I enjoyed this post of yours and I must say that everytime I come back to your blog, I always have something new and informative to read. Thanks for keeping me updated.

  • Feste private Roma

    15/02/2011 3:52:51 AM |

    Hi, I found your post really helpful. It helped me all the way in completing my assignment, I am also giving a referance link of your blog in my case study. Thanks for posting such informative content. Keep posting.

  • Cheap Shoes

    20/02/2011 5:47:22 PM |

    Read your article, I learn a lot. thank you for sharing.

  • Gevalia Coffee

    22/02/2011 12:43:36 AM |

    This site is quite interesting and I visit it often.I loved reading it and look regularly for updates to get something new. Quite informative....

  • writing dissertation

    8/03/2011 6:25:10 AM |

    :)  I must appreciate you for the post you have shared. . I really like it. . thank you for sharing :)

  • Academic Writing

    14/03/2011 9:48:57 PM |

    I found your blog while searching my topic and your blog completes my material thanks hope you will keep me up to date.

  • Academic writing

    19/04/2011 9:12:57 PM |

    I am surfing via google and i found your blog full of interesting material and i am wondering that you will keep updated thanks.

  • GHD Straightener Outlet

    17/05/2011 12:49:52 AM |

    daddies were definitely skeptics or simply Deists; these precisely designated a good secular governing administration using an "unbreachable wall" somewhere between school together with status; these quite possibly submitted within the treaty when using the Moslem united states for Tripoli a transparent fact the fact that, distinct from European countries, any "United Reports is not really, in any feel, a good Dean jerrod united states. " (So appears fully understood was initially any standard for split for school together with status rich that your treaty flushed Our elected representatives without having disagreement regarding the fact that term, together with Director Mark Adams autographed it all at any one time, without having panic that this may perhaps endanger this political near future. )

  • Home Improvement and Interior Design

    21/05/2011 8:10:53 PM |

    The beauty of these blogging engines and CMS platforms is the lack of limitations and ease of manipulation that allows developers to implement rich content and 'skin' the site in such a way that with very little effort one would never notice what it is making the site tick all without limiting content and effectiveness.

  • Sky Blue Credit Review

    21/05/2011 10:32:24 PM |

    It's great to find an author that knows their niche so amazingly well.  I will be sure to check in again to find out what is new.

  • custom car accessories

    22/05/2011 2:08:14 AM |

    Continue to make good posts like this, I will bookmark this page.

  • Mitchell Buonaiuto

    29/06/2014 7:28:13 AM |

    suprax shortage <a href="http://support.sentilla.com/entries/69712438-FDA-Approved-Fiximark-200mg-With-E-Check-in-Southampton-cefixime-in-us">http://support.sentilla.com/entries/69712438-FDA-Approved-Fiximark-200mg-With-E-Check-in-Southampton-cefixime-in-us</a> suprax used uti ofloxacin and cefixime!

  • Gala Helena

    13/07/2014 9:52:27 PM |

    difference between proair ventolin inhalers <a href="http://seogerpbooburs.webpin.com/blog_221448_Where-To-Order-Online-Albuterol-4mg-With-10--Discount-in-Salvador-ventolin-sirup-baby.html">http://seogerpbooburs.webpin.com/blog_221448_Where-To-Order-Online-Albuterol-4mg-With-10--Discount-in-Salvador-ventolin-sirup-baby.html</a> ventolin relion inhaler cost ventolin canada.

  • Illa Moede

    28/07/2014 7:53:13 PM |

    prednisolone sodium phosphate storage <a href="http://exjaperpa1984.svbtle.com/fda-approved-orasone-online-pharmacy-no-membership-in-carlton-1">http://exjaperpa1984.svbtle.com/fda-approved-orasone-online-pharmacy-no-membership-in-carlton-1</a> manage prednisone

Pingbacks and trackbacks (1)+

Comments are closed