Invalid API key

 
    • mars478 sa...
    • Användare
    • 19 nov 2010, 18:57

    Invalid API key

    I`m writing my own scrobbler on java and i had a problem: one of my methods returns me exception "java.io.IOException: Server returned HTTP response code: 403 for URL". When I copying request to browser manually i`m having:
    <lfm status="failed">
    <error code="10">
    Invalid API key - You must be granted a valid key by last.fm
    </error>
    </lfm>
    Here it is (Java):

    ...
    username=usr;
    password=psw;
    try{
    authToken=MD5.getMD5(username + MD5.getMD5(password));
    APISig= MD5.getMD5("api_key"+apiKey+"authToken"+authToken+"methodauth.getMobileSessionmysecret");
    HR.setAPISig(APISig);
    HR.setauthToken(authToken);

    HR.auth_getToken(); //ok
    HR.auth_getSession(); //error
    }
    catch(Exception e){
    e.printStackTrace();
    }
    ...

    ...

    public boolean auth_getToken(){
    LinkedList<String> LL=
    request(Root+"auth.getToken&api_key="
    +APIKey
    +"&api_sig"
    +APISig
    );
    String Str=LL.get(2);
    String temp=Str.substring(Str.lastIndexOf("<token>")+7,Str.indexOf("</token>"));
    Token=temp;
    System.out.println("in auth_getToken");
    return true;
    }

    public boolean auth_getSession(){
    LinkedList<String> LL=
    request(Root+"auth.getSession&token="+Token
    +"&api_key"+APIKey
    +"&api_sig="+APISig
    );
    for (int i=0;i<LL.size();i++)
    System.out.println(LL.get(i));
    return true;
    }


    request(String request) method is for sure working, auth_getToken() too. Where is the mistake?
    Sry for my english.

    • mars478 sa...
    • Användare
    • 20 nov 2010, 07:39
    I founded some mistakes:
    public boolean auth_getToken(){
    ...
    request(Root+"auth.getToken&api_key="
    +APIKey
    +"&api_sig=" //!!!
    +APISig
    );
    ....
    }

    and

    public boolean auth_getSession(){
    LinkedList<String> LL=
    request(Root+"auth.getSession&token="+Token
    +"&api_key="+APIKey //!!!
    ....
    }

    Now I have this error:

    <error code="13">
    Invalid method signature supplied
    </error>

    I think there can be an error in creating api_sig, is it true?:

    APISig= MD5.getMD5("api_key"+apiKey+"methodauth.getSessiontoken"+Token+secret);

    • tburny sa...
    • Forum Moderator
    • 21 nov 2010, 23:14
    hey the lastfmlib group is only for lastfmlib.net ;) I moved it into the proper place :)

    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.