Invalid method signature supplied

 
  • Invalid method signature supplied

    Solved.


    Hi, everybody.
    I have some problem with user.shout method. Or with the signature, a don't know.
    When i try to shout, i recieved this error
    Invalid method signature supplied

    Here is the code

    function get_signature($method, $token, $api_key, $secret) {
    $request = 'api_key'.$api_key.'method'.$method.'token'.$token.$secret;
    $signature = md5($request);
    return $signature;
    }

    function get_xml ($url, $params) {
    $options = array (
    CURLOPT_URL => $url,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_HEADER => false,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $params,
    CURLOPT_RETURNTRANSFER => true
    );

    $ch = curl_init();
    curl_setopt_array($ch, $options);
    $response = curl_exec($ch);
    $xml = simplexml_load_string($response);
    return $xml;
    }


    if(isset($_GET['token'])) {
    $token = $_GET['token'];

    $signature = get_signature('auth.getSession', $token, $apiKey, $secret);
    $get_session_params = 'method=auth.getSession' . '&token=' . $token . '&api_key=' . $apiKey . '&api_sig=' . $signature;
    $session = get_xml($rest_url, $get_session_params);

    $sk = $session->session->key.'';

    $signature = get_signature('user.Shout', $token, $apiKey, $secret);
    print_arr('sig 1 - ' . $signature);
    $request = 'api_key'.$apiKey.'methoduser.Shout'.'token'.$token.$secret;
    $signature = md5($request);
    print_arr('sig 2 - ' . $signature);
    $friend_name = $friend->user->name . '';
    $shout_params = 'method=user.Shout' .
    '&user=Ermekcs' .
    '&message=test' .
    '&api_key=' . $apiKey .
    '&api_sig=' . $signature .
    '&sk=' . $sk;
    $shout = get_xml($rest_url, $shout_params);
    }

    Where is the problem? I really can't find it :(

    • tburny ha detto...
    • Forum Moderator
    • Gen 11 2012, 14:53
    You have to build the signature over ALL parameters except the api-signature and the format parameter(?).
    Take a walk, then re-read the documentation carefully and you will be enlightened :)

    Oh and there already is an API for PHP, see /api/downloads

    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 :)
Gli utenti anonimi non possono inviare messaggi. Per inserire messaggi nei forum, accedi o crea il tuo account.