doxn43207 2013-10-29 23:25
浏览 25
已采纳

使用LastFM API打印出相册; 在非对象错误上调用成员函数search()

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)

  • 写回答

1条回答 默认 最新

  • dpfl37651 2013-11-03 17:52
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测