Using LastFM API to print out albums; call to a member function search() on a non-object error

StackOverflow https://stackoverflow.com/questions/19671028

  •  01-07-2022
  •  | 
  •  

Pergunta

I am trying to implement the LastFM API to print out some albums using the package seen here: https://github.com/matto1990/PHP-Last.fm-API

I have the following function in a controller:

public function album_print() {

        // Put the auth data into an array
        $authVars = array(
                'apiKey' => '*******************************',
                'secret' => '*******************************',
        );

        $config = array(
            'enabled' => true,
            'path' => '/Applications/MAMP/htdocs/**********/*****************/app/lastfmapi/',
            'cache_length' => 1800
        );

        // Pass the array to the auth class to return a valid auth
        $auth = new lastfmApiAuth('getsession', $authVars);

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

        // Setup the variables
        $methodVars = array(
        'album' => 'In Rainbows',
        'page' => 1,
        'limit' => 10
        );

        if ( $results = $albumClass->search($methodVars) ) {
        echo '<b>Data Returned</b>';
        echo '<pre>';
        print_r($results);
        echo '</pre>';
        }
        else {

        die('<b>Error '.$albumClass->error['code'].' - </b><i>'.$albumClass->error['desc'].'</i>');

        }

    }

I am trying to use the album.search function to find the album from a given input. However, when I run this, I get the following error:

Call to a member function search() on a non-object

Any idea why this would be happening? I followed the example here: https://github.com/matto1990/PHP-Last.fm-API/blob/master/examples/album.search/index.php

more or less. Thank you for your help. (This is in a controller in Laravel 4)

Foi útil?

Solução

This required an access token. This why the object was not being read correctly.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top