API full auth help.

 
  • API full auth help.

    Im trying to create a full authentication session, but im having problems.

    When launching:
    $authVars['apiKey'] = 'xxx;
    $auth = new lastfmApiAuth('getsession', $authVars);

    to start go to the api/callback page so I can get my $token, it simply fails to do anything.

    The examples also fail to work, due to the auth example not working.
    I have checekd the paths and apikey/secret values also.
    Any ideas, thanks.
    Jamie.

  • Hi,

    To get a token you need to send users to this url:

    http://www.last.fm/api/auth/?api_key=YOUR_API_KEY

    The best way to do this would be with a link or a header location redirect. Once the user accepts the api request they will be redirected back to the callback page (which you can set in your API account settings) with a $_GET variable called token. Use this, your api key and your secret to make a full auth with the code bellow:

    $vars = array(
    'apiKey' => API_KEY
    'secret' => SECRET,
    'token' => $_GET['token']
    );
    $auth = new lastfmApiAuth('getsession', $vars);

    Hope this helps :)

    Matt

    ONGOING PROJECT! PHP Last.FM API (Download or SVN)
    Online Last.FM Player (Updated version is SVN only currently)
  • Ahah! This makes much more sense now :)
    I don't know how I was getting so confused!
    Thank you for the help and the great library!

  • No problem, glad you got it sorted.

    ONGOING PROJECT! PHP Last.FM API (Download or SVN)
    Online Last.FM Player (Updated version is SVN only currently)
    • slope_mk2 escribió...
    • Usuario
    • 18 Jun 2011, 11:49
    Hi there!

    I'm usig the code in here in the examples of the phplastfmapi:

    <?php

    // Include the API
    require '../../lastfmapi/lastfmapi.php';


    $auth = new lastfmApiAuth('getsession', $vars);

    $authVars = array(
    'apiKey' => 'MY_API',
    'secret' => 'MY_SECRET',
    'token' => $_GET['token']
    );

    $auth = new lastfmApiAuth('getsession', $authVars);

    // Get the session auth data
    $file = fopen('../auth.txt', 'r');
    // Put the auth data into an array
    $authVars = array(
    'apiKey' => trim(fgets($file)),
    'secret' => trim(fgets($file)),
    'username' => trim(fgets($file)),
    'sessionKey' => trim(fgets($file)),
    'subscriber' => trim(fgets($file))
    );
    $config = array(
    'enabled' => true,
    'path' => '../../lastfmapi/',
    'cache_length' => 1800
    );
    // Pass the array to the auth class to eturn a valid auth
    $auth = new lastfmApiAuth('setsession', $authVars);

    // Call for the album package class with auth data
    $apiClass = new lastfmApi();
    $artistClass = $apiClass->getPackage($auth, 'artist', $config);

    // Setup the variables
    $methodVars = array(
    'artist' => 'Athlete',
    );

    if ( $events = $artistClass->getEvents($methodVars) ) {
    echo '<b>Data Returned</b>';
    echo '<pre>';
    print_r($events);
    echo '</pre>';
    }
    else {
    die('<b>Error '.$artistClass->error['code'].' - </b><i>'.$artistClass->error['desc'].'</i>');
    }

    ?>

    but all I get is an error:

    Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in XXX/lastfmapi/class/apibase.php on line 16

    Can anyone gibe me a hint what the problem is?

    <a href="http://www.profilneurotiker.com/"; target="_blank">www.profilneurotiker.com</a>; (German speaking)
    • slope_mk2 escribió...
    • Usuario
    • 18 Jun 2011, 13:38
    Ok, I figured out that I had php4 running on my srver, now I switched to php5 and get the following error:

    Fatal error: Call to a member function getEvents() on a non-object in XXX/phplastfmapi/examples/artist.getevents/index.php on line 44

    <a href="http://www.profilneurotiker.com/"; target="_blank">www.profilneurotiker.com</a>; (German speaking)
    • slope_mk2 escribió...
    • Usuario
    • 18 Jun 2011, 14:56
    got a little bit further, I'm continuing my issue here:

    http://www.lastfm.de/group/Last.fm+Web+Services/forum/21604/_/751207

    <a href="http://www.profilneurotiker.com/"; target="_blank">www.profilneurotiker.com</a>; (German speaking)
Los usuarios anónimos no pueden escribir mensajes. Para participar en los foros inicia sesión o crea una cuenta.