Novo

Forum kao aplikacija na telefonu

Dodajte forum na početni ekran i koristite ga kao aplikaciju, sa menijem na dnu ekrana.

  • 5 odgovora
  • 3.211 pregleda

Najnovija ↓

Ucitavanje podataka sa last.fm 07.04.2012. u 10:45 · pre 177 meseci #1
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.
Potpis
deWhite
Re: Ucitavanje podataka sa last.fm 07.04.2012. u 11:11 · pre 177 meseci #3
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";
Potpis
deWhite
Re: Ucitavanje podataka sa last.fm 09.04.2012. u 12:37 · pre 177 meseci
izmenjeno 1 put, poslednji put ilija666 09.04.2012. u 12:50
  1. ilija66609.04.2012. u 12:50zapis iz teksta poruke
#6
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.
Potpis
deWhite
Prijavite se da biste odgovorili u ovoj temi.PrijavaRegistracija

Premeštanje teme