1

Xbox music integration – windows phone

So you’ve created a Windows Phone app that has something to do with music? Well chances are you can gain some money with it thanks to the Xbox music affiliate program!
All you need to know to get this up and running is available on MSDN here… but let me show you my implementation, because I find the docs on MSDN a bit chaotic.

So first things first, open up a publishers account on Rakuten Linkshare through this url http://www.linkshare.com/join/ This is needed, because they are the ones gathering the click information and doing the payments.

* Pro tip * Note that at one point you’ll need to fill in website info – here you’ll have to put the URL pointing to your app in the windows phone app store! This is important, because that way Xbox music can verify your request ( more on this later on ).

* Pro tip * Be sure to take into account that you’ll need to fill in form W-8BEN if you live outside of the United States, for being in order of payment taxes!

After you filled in all the needed info and your account is in order, open the LinkShare website and navigate to PROGRAMS > Categories – select category Entertainment > Music and look for Xbox Music and press the Apply button on the right side.

LinkShare

When you apply for a new advertiser, you’ll get an email notification stating that it will take 1 till 2 weeks before your application is approved! And here comes the important pro tip from above, this validation is done based on the app url you submitted earlier. So you’ll first need to add a working app to the store.

After a positive review, your app will be approved for generating links to LinkShare. So the coding/integration can begin!
In my app ConcertWall I wanted to show albums from a specific artist and when the user presses the image from that album, it will show Xbox music so you could play/purchase that album.

To get started with using the REST API service of Xbox Music, you’ll need to get a Client ID and Client Secret for your app. This can be obtained via https://datamarket.azure.com/ – you’ll need to register and add the app. All the details and steps are outlined on MSDN here…
With this info you then can set up your first method to interact with the service!

When you want to gather data, you’ll first need to request an access token from the OAuth service before you can perform any REST calls to the Xbox Music service. I’ve packed this call in an async method called RequestAccessToken.

It needs your client id and secret ( the ones you created on the DataMarket.Azure site ), a given scope – this is a fixed string http://music.xboxlive.com all this has to be passed to the token service – this is https://datamarket.accesscontrol.windows.net/v2/OAuth2-13 – as a http POST. You’ll get a response back that contains the needed access token.

This token allows you to do any HTTP Get REST requests to the Xbox Music service for a specific period. In my case I just wanted to show all albums of a given artist. I wrapped this in a method called GetArtistAlbums

The Service Request string is composed of different parts, let me show you each one

  • First the base url: _artistSearch = https://music.xboxlive.com/1/content/music/search?q={0}
    • So we are going to perform a search with a given keyword
  • The keyword: artistName = the input parameter of this method
  • We want albums so add: &filters=Albums
    • You can search for other items, be sure to check out the MSDN documentation
  • Add the access token: _xboxMusicRESTRequest = “&accessToken=Bearer+”
  • Concat with the actual urlencoded token: new Uri(serviceRequest + HttpUtility.UrlEncode(accessToken))

With that in place, you just fire a client.GetAsync() and the response return value will be a JSON string containing all found Albums mathing your search string. I found that this can be a big set with to much hits, so I filter out all albums that don’t have the given artist name in the artists list of each album!

* Pro tip * Do note we aren’t yet earning any money! For this we need to add Deep Links to Xbox music on our phone.

I now present these albums in a list so the user can press the image, with this I’m activating the Deep Link url to Xbox Music on the phone.

Albums

The correct deep link uri for each album is actually already inside the response result we got from our search query, but to gain money through LinkShare we need to modify it!
We need to reroute our request through LinkShare with the correct id’s so that LinkShare can track the requests and if needed award us points!

The correct link format is show below, only thing missing is your affiliate key for Xbox music – this id can be found by generating a link on the LinkShare site for Xbox music after your request for this advertiser has been approved! Just press the Get Link button and look for the http://ad.linksynergy.com/fs-bin/show?id= part it shows you the id!

But how do you use this deep link? Well put a WebBrowser control on your windows phone page and set it Collapsed.

Only thing left is triggering the navigation on this control with the given deep link url!

* Pro tip * Instead of doing this yourself, you can use this XBox music API wrapper ( pcl ) ! It contains all needed REST calls and also provides the possibility to add your affiliate id!

Happy money gaining!

Depechie

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *