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.

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.

<span id="lnum1" style="color: #606060"> 1:</span> <span style="color: #0000ff">private</span> async Task<<span style="color: #0000ff">string</span>> RequestAccessToken() 1 < span id = "lnum1" style = "color: #606060" > 1 : < / span > < span style = "color: #0000ff" > private < / span > async Task & lt ; < span style = "color: #0000ff" > string < / span > & gt ; RequestAccessToken ( ) <span id="lnum2" style="color: #606060"> 2:</span> { 1 < span id = "lnum2" style = "color: #606060" > 2 : < / span > { <span id="lnum3" style="color: #606060"> 3:</span> HttpClient client = <span style="color: #0000ff">new</span> HttpClient(); 1 < span id = "lnum3" style = "color: #606060" > 3 : < / span > HttpClient client = < span style = "color: #0000ff" > new < / span > HttpClient ( ) ; <span id="lnum4" style="color: #606060"> 4:</span> 1 < span id = "lnum4" style = "color: #606060" > 4 : < / span > & nbsp ; <span id="lnum5" style="color: #606060"> 5:</span> <span style="color: #008000">//Create the request data</span> 1 < span id = "lnum5" style = "color: #606060" > 5 : < / span > < span style = "color: #008000" > //Create the request data</span> <span id="lnum6" style="color: #606060"> 6:</span> var requestData = <span style="color: #0000ff">new</span> Dictionary<<span style="color: #0000ff">string</span>, <span style="color: #0000ff">string</span>>(); 1 < span id = "lnum6" style = "color: #606060" > 6 : < / span > var requestData = < span style = "color: #0000ff" > new < / span > Dictionary & lt ; < span style = "color: #0000ff" > string < / span > , < span style = "color: #0000ff" > string < / span > & gt ; ( ) ; <span id="lnum7" style="color: #606060"> 7:</span> requestData[<span style="color: #006080">"client_id"</span>] = _clientID; 1 < span id = "lnum7" style = "color: #606060" > 7 : < / span > requestData [ < span style = "color: #006080" > "client_id" < / span > ] = _clientID ; <span id="lnum8" style="color: #606060"> 8:</span> requestData[<span style="color: #006080">"client_secret"</span>] = _clientSecret; 1 < span id = "lnum8" style = "color: #606060" > 8 : < / span > requestData [ < span style = "color: #006080" > "client_secret" < / span > ] = _clientSecret ; <span id="lnum9" style="color: #606060"> 9:</span> requestData[<span style="color: #006080">"scope"</span>] = _xboxMusicService; 1 < span id = "lnum9" style = "color: #606060" > 9 : < / span > requestData [ < span style = "color: #006080" > "scope" < / span > ] = _xboxMusicService ; <span id="lnum10" style="color: #606060"> 10:</span> requestData[<span style="color: #006080">"grant_type"</span>] = <span style="color: #006080">"client_credentials"</span>; 1 < span id = "lnum10" style = "color: #606060" > 10 : < / span > requestData [ < span style = "color: #006080" > "grant_type" < / span > ] = < span style = "color: #006080" > "client_credentials" < / span > ; <span id="lnum11" style="color: #606060"> 11:</span> 1 < span id = "lnum11" style = "color: #606060" > 11 : < / span > & nbsp ; <span id="lnum12" style="color: #606060"> 12:</span> <span style="color: #008000">//Post the request and retrieve the response</span> 1 < span id = "lnum12" style = "color: #606060" > 12 : < / span > < span style = "color: #008000" > //Post the request and retrieve the response</span> <span id="lnum13" style="color: #606060"> 13:</span> var response = await client.PostAsync(<span style="color: #0000ff">new</span> Uri(_tokenService), <span style="color: #0000ff">new</span> FormUrlEncodedContent(requestData)); 1 < span id = "lnum13" style = "color: #606060" > 13 : < / span > var response = await client . PostAsync ( < span style = "color: #0000ff" > new < / span > Uri ( _tokenService ) , < span style = "color: #0000ff" > new < / span > FormUrlEncodedContent ( requestData ) ) ; <span id="lnum14" style="color: #606060"> 14:</span> response.EnsureSuccessStatusCode(); 1 < span id = "lnum14" style = "color: #606060" > 14 : < / span > response . EnsureSuccessStatusCode ( ) ; <span id="lnum15" style="color: #606060"> 15:</span> <span style="color: #0000ff">string</span> responseBody = await response.Content.ReadAsStringAsync(); 1 < span id = "lnum15" style = "color: #606060" > 15 : < / span > < span style = "color: #0000ff" > string < / span > responseBody = await response . Content . ReadAsStringAsync ( ) ; <span id="lnum16" style="color: #606060"> 16:</span> 1 < span id = "lnum16" style = "color: #606060" > 16 : < / span > & nbsp ; <span id="lnum17" style="color: #606060"> 17:</span> Token token = JsonConvert.DeserializeObject<Token>(responseBody); 1 < span id = "lnum17" style = "color: #606060" > 17 : < / span > Token token = JsonConvert . DeserializeObject & lt ; Token & gt ; ( responseBody ) ; <span id="lnum18" style="color: #606060"> 18:</span> <span style="color: #0000ff">return</span> token.access_token; 1 < span id = "lnum18" style = "color: #606060" > 18 : < / span > < span style = "color: #0000ff" > return < / span > token . access_token ; <span id="lnum19" style="color: #606060"> 19:</span> } 1 < span id = "lnum19" style = "color: #606060" > 19 : < / span > }

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

<span id="lnum1" style="color: #606060"> 1:</span> <span style="color: #0000ff">public</span> async Task<List<Album>> GetArtistAlbums(<span style="color: #0000ff">string</span> artistName) 1 < span id = "lnum1" style = "color: #606060" > 1 : < / span > < span style = "color: #0000ff" > public < / span > async Task & lt ; List & lt ; Album & gt ; & gt ; GetArtistAlbums ( < span style = "color: #0000ff" > string < / span > artistName ) <span id="lnum2" style="color: #606060"> 2:</span> { 1 < span id = "lnum2" style = "color: #606060" > 2 : < / span > { <span id="lnum3" style="color: #606060"> 3:</span> List<Album> artistAlbums = <span style="color: #0000ff">null</span>; 1 < span id = "lnum3" style = "color: #606060" > 3 : < / span > List & lt ; Album & gt ; artistAlbums = < span style = "color: #0000ff" > null < / span > ; <span id="lnum4" style="color: #606060"> 4:</span> <span style="color: #0000ff">try</span> 1 < span id = "lnum4" style = "color: #606060" > 4 : < / span > < span style = "color: #0000ff" > try < / span > <span id="lnum5" style="color: #606060"> 5:</span> { 1 < span id = "lnum5" style = "color: #606060" > 5 : < / span > { <span id="lnum6" style="color: #606060"> 6:</span> <span style="color: #0000ff">string</span> accessToken = await <span style="color: #0000ff">this</span>.RequestAccessToken(); 1 < span id = "lnum6" style = "color: #606060" > 6 : < / span > < span style = "color: #0000ff" > string < / span > accessToken = await < span style = "color: #0000ff" > this < / span > . RequestAccessToken ( ) ; <span id="lnum7" style="color: #606060"> 7:</span> 1 < span id = "lnum7" style = "color: #606060" > 7 : < / span > & nbsp ; <span id="lnum8" style="color: #606060"> 8:</span> <span style="color: #008000">//Use the token in a new request</span> 1 < span id = "lnum8" style = "color: #606060" > 8 : < / span > < span style = "color: #008000" > //Use the token in a new request</span> <span id="lnum9" style="color: #606060"> 9:</span> HttpClient client = <span style="color: #0000ff">new</span> HttpClient(); 1 < span id = "lnum9" style = "color: #606060" > 9 : < / span > HttpClient client = < span style = "color: #0000ff" > new < / span > HttpClient ( ) ; <span id="lnum10" style="color: #606060"> 10:</span> 1 < span id = "lnum10" style = "color: #606060" > 10 : < / span > & nbsp ; <span id="lnum11" style="color: #606060"> 11:</span> <span style="color: #0000ff">string</span> serviceRequest = <span style="color: #0000ff">string</span>.Format(_artistSearch, artistName); 1 < span id = "lnum11" style = "color: #606060" > 11 : < / span > < span style = "color: #0000ff" > string < / span > serviceRequest = < span style = "color: #0000ff" > string < / span > . Format ( _artistSearch , artistName ) ; <span id="lnum12" style="color: #606060"> 12:</span> serviceRequest = <span style="color: #0000ff">string</span>.Concat(serviceRequest, <span style="color: #006080">"&filters=Albums"</span>); 1 < span id = "lnum12" style = "color: #606060" > 12 : < / span > serviceRequest = < span style = "color: #0000ff" > string < / span > . Concat ( serviceRequest , < span style = "color: #006080" > "&filters=Albums" < / span > ) ; <span id="lnum13" style="color: #606060"> 13:</span> serviceRequest = <span style="color: #0000ff">string</span>.Concat(serviceRequest, _xboxMusicRESTRequest); 1 < span id = "lnum13" style = "color: #606060" > 13 : < / span > serviceRequest = < span style = "color: #0000ff" > string < / span > . Concat ( serviceRequest , _xboxMusicRESTRequest ) ; <span id="lnum14" style="color: #606060"> 14:</span> 1 < span id = "lnum14" style = "color: #606060" > 14 : < / span > & nbsp ; <span id="lnum15" style="color: #606060"> 15:</span> var response = await client.GetAsync(<span style="color: #0000ff">new</span> Uri(serviceRequest + HttpUtility.UrlEncode(accessToken))); 1 < span id = "lnum15" style = "color: #606060" > 15 : < / span > var response = await client . GetAsync ( < span style = "color: #0000ff" > new < / span > Uri ( serviceRequest + HttpUtility . UrlEncode ( accessToken ) ) ) ; <span id="lnum16" style="color: #606060"> 16:</span> <span style="color: #0000ff">string</span> responseBody = await response.Content.ReadAsStringAsync(); 1 < span id = "lnum16" style = "color: #606060" > 16 : < / span > < span style = "color: #0000ff" > string < / span > responseBody = await response . Content . ReadAsStringAsync ( ) ; <span id="lnum17" style="color: #606060"> 17:</span> AlbumsResponse albumsResponse = JsonConvert.DeserializeObject<AlbumsResponse>(responseBody); 1 < span id = "lnum17" style = "color: #606060" > 17 : < / span > AlbumsResponse albumsResponse = JsonConvert . DeserializeObject & lt ; AlbumsResponse & gt ; ( responseBody ) ; <span id="lnum18" style="color: #606060"> 18:</span> 1 < span id = "lnum18" style = "color: #606060" > 18 : < / span > <span id="lnum19" style="color: #606060"> 19:</span> <span style="color: #0000ff">if</span> (!ReferenceEquals(albumsResponse, <span style="color: #0000ff">null</span>) && !ReferenceEquals(albumsResponse.Albums, <span style="color: #0000ff">null</span>)) 1 < span id = "lnum19" style = "color: #606060" > 19 : < / span > < span style = "color: #0000ff" > if < / span > ( ! ReferenceEquals ( albumsResponse , < span style = "color: #0000ff" > null < / span > ) & amp ; & amp ; ! ReferenceEquals ( albumsResponse . Albums , < span style = "color: #0000ff" > null < / span > ) ) <span id="lnum20" style="color: #606060"> 20:</span> { 1 < span id = "lnum20" style = "color: #606060" > 20 : < / span > { <span id="lnum21" style="color: #606060"> 21:</span> artistAlbums = (from album <span style="color: #0000ff">in</span> albumsResponse.Albums.Items 1 < span id = "lnum21" style = "color: #606060" > 21 : < / span > artistAlbums = ( from album < span style = "color: #0000ff" > in < / span > albumsResponse . Albums . Items <span id="lnum22" style="color: #606060"> 22:</span> from artist <span style="color: #0000ff">in</span> album.Artists 1 < span id = "lnum22" style = "color: #606060" > 22 : < / span > from artist < span style = "color: #0000ff" > in < / span > album . Artists <span id="lnum23" style="color: #606060"> 23:</span> <span style="color: #0000ff">where</span> artist.Artist.Name.Equals(artistName, StringComparison.OrdinalIgnoreCase) 1 < span id = "lnum23" style = "color: #606060" > 23 : < / span > < span style = "color: #0000ff" > where < / span > artist . Artist . Name . Equals ( artistName , StringComparison . OrdinalIgnoreCase ) <span id="lnum24" style="color: #606060"> 24:</span> select album).ToList(); 1 < span id = "lnum24" style = "color: #606060" > 24 : < / span > select album ) . ToList ( ) ; <span id="lnum25" style="color: #606060"> 25:</span> } 1 < span id = "lnum25" style = "color: #606060" > 25 : < / span > } <span id="lnum26" style="color: #606060"> 26:</span> } 1 < span id = "lnum26" style = "color: #606060" > 26 : < / span > } <span id="lnum27" style="color: #606060"> 27:</span> <span style="color: #0000ff">catch</span> (Exception) 1 < span id = "lnum27" style = "color: #606060" > 27 : < / span > < span style = "color: #0000ff" > catch < / span > ( Exception ) <span id="lnum28" style="color: #606060"> 28:</span> { 1 < span id = "lnum28" style = "color: #606060" > 28 : < / span > { <span id="lnum29" style="color: #606060"> 29:</span> <span style="color: #008000">//There was a problem with getting the albums, return null to be sure the program continues</span> 1 < span id = "lnum29" style = "color: #606060" > 29 : < / span > < span style = "color: #008000" > //There was a problem with getting the albums, return null to be sure the program continues</span> <span id="lnum30" style="color: #606060"> 30:</span> } 1 < span id = "lnum30" style = "color: #606060" > 30 : < / span > } <span id="lnum31" style="color: #606060"> 31:</span> 1 < span id = "lnum31" style = "color: #606060" > 31 : < / span > & nbsp ; <span id="lnum32" style="color: #606060"> 32:</span> <span style="color: #0000ff">return</span> artistAlbums; 1 < span id = "lnum32" style = "color: #606060" > 32 : < / span > < span style = "color: #0000ff" > return < / span > artistAlbums ; <span id="lnum33" style="color: #606060"> 33:</span> } 1 < span id = "lnum33" style = "color: #606060" > 33 : < / span > }

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.

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!

<span id="lnum1" style="color: #606060"> 1:</span> <span style="color: #0000ff">string</span>.Format(<span style="color: #006080">"http://click.linksynergy.com/deeplink?id={0}&mid=39033&murl={1}"</span>, <span style="color: #006080">"{your Xbox music LinkShare id}"</span>, HttpUtility.UrlEncode(<span style="color: #0000ff">string</span>.Concat(item.Link, <span style="color: #006080">"&action=play"</span>))) 1 < span id = "lnum1" style = "color: #606060" > 1 : < / span > < span style = "color: #0000ff" > string < / span > . Format ( < span style = "color: #006080" > "http://click.linksynergy.com/deeplink?id={0}&mid=39033&murl={1}" < / span > , < span style = "color: #006080" > "{your Xbox music LinkShare id}" < / span > , HttpUtility . UrlEncode ( < span style = "color: #0000ff" > string < / span > . Concat ( item . Link , < span style = "color: #006080" > "&action=play" < / span > ) ) )

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

<span id="lnum1" style="color: #606060"> 1:</span> <phone:WebBrowser x:Name=<span style="color: #006080">"HiddenWebBrowser"</span> Visibility=<span style="color: #006080">"Collapsed"</span> /> 1 < span id = "lnum1" style = "color: #606060" > 1 : < / span > & lt ; phone : WebBrowser x : Name = < span style = "color: #006080" > "HiddenWebBrowser" < / span > Visibility = < span style = "color: #006080" > "Collapsed" < / span > / & gt ;

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

<span id="lnum1" style="color: #606060"> 1:</span> HiddenWebBrowser.Navigate(<span style="color: #0000ff">new</span> Uri(message.MusicLink)) 1 < span id = "lnum1" style = "color: #606060" > 1 : < / span > HiddenWebBrowser . Navigate ( < span style = "color: #0000ff" > new < / span > Uri ( message . MusicLink ) )

* 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!