Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Ucitavanje podataka sa last.fm

[es] :: PHP :: PHP za početnike :: Ucitavanje podataka sa last.fm

[ Pregleda: 2088 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

ilija666

Član broj: 70361
Poruke: 16
178.79.24.*

Sajt: www.last.fm/music/Endless..


Profil

icon Ucitavanje podataka sa last.fm07.04.2012. u 09:45 - pre 145 meseci
Pokusavam da odradim jednu prostu skripticu, ali dobijam blank output:

index.html
Code:
<form action="form_action.php" method="get">
   Upišite vaš omiljen bend i dobicete kao rezultat njemu slicne bendove i njihove najbolje albume.<br />
   Vas omiljen bend: <input type="text" name="fname" /><br />
   Broj bendova za prikazivanje:<br />
<select name="Broj_bendova">
<option value="5">5</option>
<option value="10">10</option>
<option value="20" selected="selected">20</option>
<option value="50">30</option>
</select>
   <input type="submit" value="Posalji" />
 </form>


form_action.php
Code:
<?
$artist=$_GET["fname"];
$brojb=$_GET["Broj_bendova"];
echo $artist;

$completeurl="http://ws.audioscrobbler.com/2...=artist.getsimilar&artist=$artist&limit=$brojb&api_key=b25b959554ed76058ac220b7b2e0a026";


$xml = simplexml_load_file($completeurl);
$artistz = $xml->lfm->similarartists->artist;

foreach ($artistz as $artist) {

echo $artists->name . "\n";
echo "<a href=" . $artists->url. ">";
}
?>


help.
deWhite
 
Odgovor na temu

Nikola Poša
Backend (PHP) developer
Beograd

Član broj: 173839
Poruke: 1616
*.adsl-a-1.sezampro.rs.



+33 Profil

icon Re: Ucitavanje podataka sa last.fm07.04.2012. u 10:00 - pre 145 meseci
A zašto ne pokušaš da iskoristiš Last.fm API? Evo koliko vidim postoji i taj neki metod koji tebi treba: http://www.last.fm/api/show/artist.search.
 
Odgovor na temu

ilija666

Član broj: 70361
Poruke: 16
178.79.24.*

Sajt: www.last.fm/music/Endless..


Profil

icon Re: Ucitavanje podataka sa last.fm07.04.2012. u 10:11 - pre 145 meseci
Ovaj, zato sto sam poceo skoro i nikada to sada to nisam radio. Cisto zanimanja radi dok ne resim ovaj problem, how do i do that?
Mislio sam da sam iskoristio jednu metodu ovim: $completeurl="http://ws.audioscrobbler.com/2...=artist.getsimilar&artist=$artist&limit=$brojb&api_key=b25b959554ed76058ac220b7b2e0a026";

deWhite
 
Odgovor na temu

peca89bg
Beograd

Član broj: 202034
Poruke: 354
95.180.69.*



+6 Profil

icon Re: Ucitavanje podataka sa last.fm07.04.2012. u 10:20 - pre 145 meseci
pogledaj i grooveshark
 
Odgovor na temu

ilija666

Član broj: 70361
Poruke: 16
178.79.24.*

Sajt: www.last.fm/music/Endless..


Profil

icon Re: Ucitavanje podataka sa last.fm07.04.2012. u 12:08 - pre 145 meseci
Stavio sam posle simplexml_load_file ovo
if($xml === FALSE)
{
echo "greska";
}
i stampa mi gresku.
znaci zbog neceg simplexml_load_file ne parsuje fajl.
i'm baffled.


deWhite
 
Odgovor na temu

ilija666

Član broj: 70361
Poruke: 16
178.79.24.*

Sajt: www.last.fm/music/Endless..


Profil

icon Re: Ucitavanje podataka sa last.fm09.04.2012. u 11:37 - pre 145 meseci
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
 
Odgovor na temu

[es] :: PHP :: PHP za početnike :: Ucitavanje podataka sa last.fm

[ Pregleda: 2088 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.