Where to start, C#

 
  • Where to start, C#

    Hello,

    I've been trying to get Last FM working for my own build audioPlayer for quite some time now. A friend showed me this link and the past 5 hours I've been trying to get this to work, unfortunately I don't understand a thing of VB so all the examples and even the documentation is nearly useless to me.

    So basically what I'm asking is where can someone as me who is "new" (as in I'm not new but I don't understand anything) to the WHOLE Last FM business start to learn?

    Thanks,

    ArmoredSandwich

    • tburny sa...
    • Forum Moderator
    • 13 sep 2008, 09:47
    hey
    first thanks for joining :)
    I recommend you to take a look at http://support.microsoft.com/kb/308470. There some M$ guy points out the differences between c# and vb.net(It's about 15 pages with lots of charts, so less stuff to read ;) ).
    Major differnce is that you have to write a semi-colon at the end of line;)
    Another is that you write "[classname] myClassVar = new [classname]([params]);" instead of "Dim myClassVar As New [classname]([params])" :)

    If you need some help about the requests, how they work and what data they provide to you, you can read the Official Last.fm API doc.
    For any other stuff which isn't in there, feel free to ask :)

    tburny

    Combo.fm: Combine your favourite radio stations! | My Blog | scala-lastfmapi | Cache2k - A high performance Java in-memory cache
    P.S.: Do not click here
    throw new PokemonException(); //Gotta catch 'em all
    My forum post reflects my personal opinion :)
  • Hey, thanks for all you've done, you're awesome!

    I'm still mostly screwing around and trying other pieces of code I can understand and find here. The biggest problem is that I have no idea what I need to just to get a nowPlayingNotification working!

    I'm writing a simple Console application to see if I can get that to work;

    static void Main(string[] args)
    {
    testLastFM();
    Console.Read();
    }

    private static void testLastFM()
    {
    LastFmUser user = ArmoredSandwichUser;
    LastFmClient client = new LastFmClient(user);
    Handshake handshake = client.Login();

    Console.WriteLine("Client login suceedded = " + handshake.succeeded);

    if (handshake.succeeded)
    {
    ScrobblerManager manager = new ScrobblerManager();
    ScrobblerInit init = new ScrobblerInit();
    init.User = user;
    // init.Version = ??;
    TrackInfo track = FastenYourSeatbeltsTrack;

    bool managerHandshakeResult = manager.Handshake(ref init);

    Console.WriteLine("ScrobblerManager's handshake result = " + managerHandshakeResult);

    if (managerHandshakeResult)
    {
    manager.NowPlayingNotification(ref track);
    }
    }
    }

    /// <summary>
    /// Returns a LastFmUser object of ArmoredSandwich' account.
    /// </summary>
    private static LastFmUser ArmoredSandwichUser
    {
    get
    {
    LastFmUser user = new LastFmUser();
    user.Username = "ArmoredSandwich";
    user.Password = password;

    // user.scrobblePoint = ??;
    // user.SessionID = ??;

    Console.WriteLine("User validated = " + user.ValidateUsernameAndPasswordMD5());

    return user;
    }
    }

    /// <summary>
    /// Is a track of Pendelum, ArmoredSandwich as username.
    /// </summary>
    private static TrackInfo FastenYourSeatbeltsTrack
    {
    get
    {
    TrackInfo track = new TrackInfo("Pendulum", "Hold your colour", "Fasten your Seatbelts");
    track.timeStampMe();

    Console.WriteLine("Track's timeStap: " + track.TimeStamp);

    track.Username = "ArmoredSandwich";

    //track.AuthCode = ??;

    return track;
    }
    }


    There are no errors, but also no results, my Last fm page shows me nothing! Could you give me a push in the right direction as in what I need and where I need to look to get that stuff?

    I've also got some nice code that accompishes something with an apiToken, especially this that code is copied from someone on this forum. I understand what's happening but I don't understand why it's happening or what I should do with it.

    I know I'm asking for a lot but to be honest, I've been trying a lot myself too, it's not as if I don't try to get this working by myself, believe me I am. It's just not working :O

    Thanks again! :)

    • tburny sa...
    • Forum Moderator
    • 14 sep 2008, 10:24
    ouch wo don't need the normal Handshake(the client.Login thing) any more, if you don't want to use the radio functions....
    track.AuthCode is only needed if you want to scrobble last.fm radio tracks
    the init.version is your app version and automatically set by default :)
    rest looks pretty fine.

    maybe see this:

    2. The Now-Playing Notification
    The Now-Playing notification is a lightweight mechanism for notifying Last.fm that a track has started playing. This is used for realtime display of a user's currently playing track, and does not affect a user's musical profile.

    The Now-Playing notification is optional, but recommended.

    The request takes the form of a group of form encoded key-value pairs which are submitted to the server as the body of a HTTP POST request, using the now-playing URL returned by the handshake request. The key-value pairs are:
    s=<sessionID>
    The Session ID string returned by the handshake request. Required.
    a=<artistname>
    The artist name. Required.
    t=<track>
    The track name. Required.
    b=<album>
    The album title, or an empty string if not known.
    l=<secs>
    The length of the track in seconds, or an empty string if not known.
    n=<tracknumber>
    The position of the track on the album, or an empty string if not known.
    m=<mb-trackid>
    The MusicBrainz Track ID, or an empty string if not known.


    session id means the one from scrobbler handshake, of course :) but lastfmlib should do this for you :)

    Combo.fm: Combine your favourite radio stations! | My Blog | scala-lastfmapi | Cache2k - A high performance Java in-memory cache
    P.S.: Do not click here
    throw new PokemonException(); //Gotta catch 'em all
    My forum post reflects my personal opinion :)
  • Well, it's still not working :P

    I got this now, but I'm not sure if this is what you mean?

    LastFmUser user = ArmoredSandwichUser;

    ScrobblerManager manager = new ScrobblerManager();
    ScrobblerInit init = new ScrobblerInit();
    init.User = user;

    TrackInfo track = FastenYourSeatbeltsTrack;

    bool managerHandshakeResult = manager.Handshake(ref init);

    Console.WriteLine("ScrobblerManager's handshake result = " + managerHandshakeResult);

    if (managerHandshakeResult)
    {
    manager.NowPlayingNotification(ref track);
    }


    Atleast the handshake result returns false now, that's something I can work with :)

    EDIT: How am I going to insert the authentication token that you need to handshake? I can imagine all the other stuff is done by the lib.

    Is there a way to see what is exactly failing when trying to shake?

    • tburny sa...
    • Forum Moderator
    • 15 sep 2008, 14:34
    well atm I just can help you with the auth token, the other stuff requires me some time I don't have yet, as theres a class test on wednesday of which the mark counts three times :(

    the auth code is set when getting the xspf playlist from the radio functions(the old ones!)

    Combo.fm: Combine your favourite radio stations! | My Blog | scala-lastfmapi | Cache2k - A high performance Java in-memory cache
    P.S.: Do not click here
    throw new PokemonException(); //Gotta catch 'em all
    My forum post reflects my personal opinion :)
  • I've been trying to get this to work for 3 days straight and I'm still getting nowhere, so I appreciate anything you can give me :)

    Good luck with your test! XD

    • tburny sa...
    • Forum Moderator
    • 15 sep 2008, 20:36
    gotcha!
    you have to either set Settings.AuthData(which i strongly recommend!) or call the constructor of init with an instance of AuthData :)

    Combo.fm: Combine your favourite radio stations! | My Blog | scala-lastfmapi | Cache2k - A high performance Java in-memory cache
    P.S.: Do not click here
    throw new PokemonException(); //Gotta catch 'em all
    My forum post reflects my personal opinion :)
  • Hey, how did your test go?

    Well I think I'm on the right track to setting authData, however I've run in a problem I can't really explain.

    Here's my code to set the 4 properties of the authData needed:

    private void setAuth()
    {
    // key
    LastFmLib.MD5Hash ApiKeyMD5Hash = new LastFmLib.MD5Hash();
    ApiKeyMD5Hash = LastFmLib.MD5Hash.FromString(apiKeyString);

    // secret
    LastFmLib.MD5Hash ApiSecretMD5Hash = new LastFmLib.MD5Hash();
    ApiSecretMD5Hash = LastFmLib.MD5Hash.FromString(apiSecretString);

    // auth
    LastFmLib.API20.Types.AuthData authData = new LastFmLib.API20.Types.AuthData(ApiKeyMD5Hash, ApiSecretMD5Hash, null);

    readAuthData(authData, 0);

    // token
    LastFmLib.API20.Auth.AuthGetToken getApiToken = new LastFmLib.API20.Auth.AuthGetToken();
    getApiToken.AuthData = authData;

    getApiToken.Start();
    if (getApiToken.succeeded)
    {
    Console.WriteLine("API token request succesfully started.");
    authData.Token = getApiToken.Result; // sets token
    }
    else
    {
    Console.WriteLine("API token request failed, api token error message: " + getApiToken.errorMessage);
    }

    readAuthData(authData, 1);

    // session
    LastFmLib.API20.Auth.AuthGetSession getSession = new LastFmLib.API20.Auth.AuthGetSession(authData.Token);
    getSession.AuthData = authData;

    getSession.Start();
    if (getSession.succeeded)
    {
    Console.WriteLine("Session has succesfully started.");
    authData.Session = getSession.Result;
    }
    else
    {
    Console.WriteLine("Session failed: " + getSession.errorMessage);
    }

    readAuthData(authData, 2);

    // set in settings
    LastFmLib.API20.Settings.AuthData = authData;
    }

    private void readAuthData(LastFmLib.API20.Types.AuthData auth , int times)
    {
    Console.WriteLine("Will now read auth data, times read: " + times);
    Console.WriteLine("- AuthData has apikey = " + auth.HasApiKey);
    Console.WriteLine("- AuthData has secret = " + auth.HasSecret);
    Console.WriteLine("- AuthData has session = " + auth.HasSession);
    Console.WriteLine("- AuthData has token = " + auth.HasToken);
    }


    Apparently the session won't succeed: "This token has not been authorized".

    Can you give me some more clues? :)

    Thanks again!

    • tburny sa...
    • Forum Moderator
    • 18 sep 2008, 20:30
    // key
    LastFmLib.MD5Hash ApiKeyMD5Hash = new LastFmLib.MD5Hash();
    ApiKeyMD5Hash = LastFmLib.MD5Hash.FromString(apiKeyString);

    you actualle hit the six lotto numbers plus super number ;) the FromString method of MD5Hash class calculates the md5 of a string and returns the new hash then. I added some xml comments which will come with the next SVN commit....

    your code would be

    LastFmLib.MD5Hash ApiKeyMD5Hash = new LastFmLib.MD5Hash(apiKeyString, true);

    if c# supports optional params you can also leave out the true, only if setting false the string will be hashed again :)

    hope this will help you :)

    Combo.fm: Combine your favourite radio stations! | My Blog | scala-lastfmapi | Cache2k - A high performance Java in-memory cache
    P.S.: Do not click here
    throw new PokemonException(); //Gotta catch 'em all
    My forum post reflects my personal opinion :)
    • tburny sa...
    • Forum Moderator
    • 20 sep 2008, 22:48
    and sorry, the scrobbler code was broken....
    now there are three samples for scrobbling in the current sample project, hope this will help

    Combo.fm: Combine your favourite radio stations! | My Blog | scala-lastfmapi | Cache2k - A high performance Java in-memory cache
    P.S.: Do not click here
    throw new PokemonException(); //Gotta catch 'em all
    My forum post reflects my personal opinion :)
    • ycs523 sa...
    • Användare
    • 22 sep 2008, 00:27
    I think you don't need token's parts.
    only following codes needed..

    LastFmLib.MD5Hash API_key = new LastFmLib.MD5Hash();
    LastFmLib.MD5Hash API_secret = new LastFmLib.MD5Hash();

    API_key = LastFmLib.MD5Hash.FromString(your_key);
    API_secret = LastFmLib.MD5Hash.FromString(your_key);


    LastFmLib.API20.Types.AuthData myAuth = new LastFmLib.API20.Types.AuthData(API_key, API_secret,null);

    //null means Not use authtoken.

    LastFmLib.API20.Settings.AuthData = myAuth;
    // Set your auth

    // finish

    but if you want use XML for auth
    you need more codes.

    Sample code. but I don't know it works because I didn't try it.
    API_token.AuthData = myAuth;
    try
    {
    API_token.Start();

    if (API_token.succeeded)
    {

    LastFmLib.API20.Settings.AuthData.Token = API_token.Result;
    LastFmLib.API20.Settings.AuthData.AskUserToGrantPermissions();
    LastFmLib.API20.Auth.AuthGetSession API_session = new LastFmLib.API20.Auth.AuthGetSession(LastFmLib.API20.Settings.AuthData.Token);
    API_session.Start();
    if (API_session.succeeded)
    {

    LastFmLib.API20.Settings.AuthData.Session = API_session.Result;

    //append Xml

    }



    }
    else
    {
    MessageBox.Show(API_token.errorMessage);
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show("faied" + ex.Message);
    }

    Redigerad av ycs523 den 22 sep 2008, 00:54
    • ycs523 sa...
    • Användare
    • 22 sep 2008, 00:34
    I have missing code. API_token is needed... (if you want XML)
    LastFmLib.API20.Auth.AuthGetToken API_token = new LastFmLib.API20.Auth.AuthGetToken();

    • tburny sa...
    • Forum Moderator
    • 26 sep 2008, 16:37
    do an auth.authGetToken request :)

    Combo.fm: Combine your favourite radio stations! | My Blog | scala-lastfmapi | Cache2k - A high performance Java in-memory cache
    P.S.: Do not click here
    throw new PokemonException(); //Gotta catch 'em all
    My forum post reflects my personal opinion :)
    • tburny sa...
    • Forum Moderator
    • 2 jan 2009, 13:44
    hows your player going ?

    Combo.fm: Combine your favourite radio stations! | My Blog | scala-lastfmapi | Cache2k - A high performance Java in-memory cache
    P.S.: Do not click here
    throw new PokemonException(); //Gotta catch 'em all
    My forum post reflects my personal opinion :)
    • zozyka sa...
    • Användare
    • 17 mar 2011, 23:51
    Hello,
    im very interested in making an C# last.fm app using your api, but i've already stuck at the start.
    Unfortunately ,I get always the same error with the sample project:

    Warning2Option 'keyfile' overrides attribute 'System.Reflection.AssemblyKeyFileAttribute' given in a source file or added modulelastfm-sharp
    Error1Cryptographic failure while signing assembly 'C:\Users\zoli\Desktop\C# - Copy\lastfm-sharp\obj\Debug\lastfm-sharp.dll' -- 'Error reading key file 'c:\Users\zoli\dropbox\projects\lastfm-sharp\trunk\src\lastfm-sharp.snk' -- The system cannot find the path specified. 'lastfm-sharp

    ----------------------
    I would be happy if You could help me out what i'm doing wrong!

    • tburny sa...
    • Forum Moderator
    • 18 mar 2011, 02:26
    hmm this has to do with assembly signing....maybe you should email the authors and file a ticket on their bug tracker:
    http://code.google.com/p/lastfm-sharp/issues/list

    Combo.fm: Combine your favourite radio stations! | My Blog | scala-lastfmapi | Cache2k - A high performance Java in-memory cache
    P.S.: Do not click here
    throw new PokemonException(); //Gotta catch 'em all
    My forum post reflects my personal opinion :)
Anonyma användare kan inte skriva inlägg. Vänligen logga in eller skapa ett konto för att göra inlägg i forumen.