Nokia MixRadio API: Getting Started

Introduction

In this article we will learn about Nokia MixRadio API authentication and App id. In my last few articles I covered the Nokia MixRadio launcher API that helps in performing some basic tasks using Nokia Mix Radio App. But the Nokia MixRadio App is more powerful than its launcher variant. It allows you to request the data from the server and you can use it in your application in your very own way. It doesn't require the pre-installation of MixRadio App.

App ID

Before we can use this API we need to generate a client id for our application. It is also called an App ID. Whenever you create any app that requires the use of this API you can generate an App id for it by visiting the Nokia Mix API web sites.

To generate an App id you can do the following:

  1. Visit the following web page https://account.mixrad.io/developer.
  2. Sign in with your Nokia developer account or you can create a new account.
  3. After signing in, click on "Add new app".
  4. On the next page enter your app name and its details. This info is displayed to the user when the user logs into your app using the Nokia account.
  5. Click on "Next" and you will get your Client Id and secret. Your client Id is your App ID.
  6. Click "Save" and you are done.

 

 
 
 
Adding MixRadio API to Project

Use the following procedure to add this API to your project:

  1. Open the Nugget Package Manager Console.
  2. Paste this code into it: Install-Package NokiaMusic
  3. Then you will get a log similar to this:
     

    Attempting to resolve dependency 'SharpGIS.GZipWebClient (≥ 1.4.0.0)'.

    Attempting to resolve dependency 'Newtonsoft.Json (≥ 5.0.6)'.

    Installing 'SharpGIS.GZipWebClient 1.4.0.0'.

    Successfully installed 'SharpGIS.GZipWebClient 1.4.0.0'.

    Installing 'Newtonsoft.Json 5.0.6'.

    Successfully installed 'Newtonsoft.Json 5.0.6'.

    Installing 'NokiaMusic 3.2.0'.

    Successfully installed 'NokiaMusic 3.2.0'.

    Adding 'SharpGIS.GZipWebClient 1.4.0.0' to Demo.

    Successfully added 'SharpGIS.GZipWebClient 1.4.0.0' to Demo.

    Adding 'Newtonsoft.Json 5.0.6' to Demo.

    Successfully added 'Newtonsoft.Json 5.0.6' to Demo.

    Adding 'NokiaMusic 3.2.0' to Demo.

    Successfully added 'NokiaMusic 3.2.0' to Demo.

     

  4. The API is added and now you can use it in your project.

Requesting Data From API

To request data from the API, you need to first create an object of the MixRadio API and then you can request the specific data using that object.

To create a MixRadio instance:

Nokia.Music.MusicClient client = new Nokia.Music.MusicClient("MyAPPID");

 

Before calling the method on the client, ensure that you are doing all this asynchronously. This API is based on the asynchronous programming model.

Example call for retrieving the list of genres:

var genre= await client.GetGenresAsync();

 

Use of await will prevent the app screen from freezing. Call to any await method must be enclosed in an async method.

Example

Before running this snippet please ensure you have added an API reference in your project. You can install this API  from the Nugget Package Manager Console.

XAML

<phone:PhoneApplicationPage

    x:Class="Demo.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"

    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    FontFamily="{StaticResource PhoneFontFamilyNormal}"

    FontSize="{StaticResource PhoneFontSizeNormal}"

    Foreground="{StaticResource PhoneForegroundBrush}"

    SupportedOrientations="Portrait" Orientation="Portrait"

    shell:SystemTray.IsVisible="True">

 

    <!--LayoutRoot is the root grid where all page content is placed-->

    <Grid x:Name="LayoutRoot" Background="Transparent">

        <Grid.RowDefinitions>

            <RowDefinition Height="Auto"/>

            <RowDefinition Height="*"/>

        </Grid.RowDefinitions>

 

        <!--TitlePanel contains the name of the application and page title-->

        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">

            <TextBlock Text="Demo" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>

            <TextBlock Text="API Data Request" Margin="9,-7,0,0" FontSize="40"/>

        </StackPanel>

 

        <!--ContentPanel - place additional content here-->

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

            <Button Name="strtBtn" Content="Get Genre" Click="chkClick" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="446"/>

            <ListBox Name="genColl" Margin="0,87,0,10"></ListBox>

        </Grid>

    </Grid>

 

</phone:PhoneApplicationPage>

 

C# Code Behind

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Navigation;

using Microsoft.Phone.Controls;

using Microsoft.Phone.Shell;

using Demo.Resources;

using System.Threading;

using Nokia.Music.Types;

 

namespace Demo

{

    public partial class MainPage : PhoneApplicationPage

    {

        // Constructor

        public MainPage()

        {

            InitializeComponent();

        }

        private async void chkClick(object sender, RoutedEventArgs e)

        {

            Nokia.Music.MusicClient client = new Nokia.Music.MusicClient("MyAPPID");

            var genre= await client.GetGenresAsync();

            foreach (var item in genre)

            {

                genColl.Items.Add(item.Name);

            }

        }

    }

}

 
 
 
Summary

That's all for this article. In my next article we will see how to use the various methods of this API and how to bind the retrieved data to the UI. In case of any confusion or doubt feel free to ask in the comments.


Similar Articles