Elem, poceo sam da se zezam sa last.fm api-jem, ali neke stvari ne mogu da provalim. Recimo, probao sam sa ovom skriptom da nesto uradim, ali bezuspesno. Cela prica oko callback-a i $_GET['token'] varijable me skroz zbunjuje.
Code:
<?php
require 'lastfmapi/lastfmapi.php';
if ( !empty($_GET['token']) ) {
$vars = array(
'apiKey' => 'moj kljuc',
'secret' => 'moj secret',
'token' => $_GET['token']
);
$auth = new lastfmApiAuth('getsession', $vars);
$file = fopen('../auth.txt', 'w');
$contents = $auth->apiKey."\n".$auth->secret."\n".$auth->username."\n".$auth->sessionKey."\n".$auth->subscriber;
fwrite($file, $contents, strlen($contents));
fclose($file);
echo 'New key has been generated and saved to auth.txt<br /><br />';
echo '<a href="'.$_SERVER['PHP_SELF'].'">Reload</a>';
}
else {
$file = fopen('../auth.txt', 'r');
$vars = array(
'apiKey' => trim(fgets($file)),
'secret' => trim(fgets($file)),
'username' => trim(fgets($file)),
'sessionKey' => trim(fgets($file)),
'subscriber' => trim(fgets($file))
);
$auth = new lastfmApiAuth('setsession', $vars);
echo '<b>API Key:</b> '.$auth->apiKey.'<br />';
echo '<b>Secret:</b> '.$auth->secret.'<br />';
echo '<b>Username:</b> '.$auth->username.'<br />';
echo '<b>Session Key:</b> '.$auth->sessionKey.'<br />';
echo '<b>Subscriber:</b> '.$auth->subscriber.'<br /><br />';
echo '<a href="http://www.last.fm/api/auth/?api_key='.$auth->apiKey.'">Get New Key</a>';
}
?>
Ideja je da ovo generise auth.txt, iz koga cu posle da vadim getSimilar metodom iz ovog koda.
Code:
<?php
// Include the API
require '../../lastfmapi/lastfmapi.php';
// 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 ( $artists = $artistClass->getSimilar($methodVars) ) {
echo '<b>Data Returned</b>';
echo '<pre>';
print_r($artists);
echo '</pre>';
}
else {
die('<b>Error '.$artistClass->error['code'].' - </b><i>'.$artistClass->error['desc'].'</i>');
}
?>
edit: uspeo sam da odradim callback, ali, iako dobijam token od last.fm/api/auth, ova prva skripta mi izbacuje prazan odgovor.
[Ovu poruku je menjao ilija666 dana 09.04.2012. u 12:50 GMT+1]
deWhite