如何修复“调用未定义函数”-PHP,mgp25

时间:2019-11-02 10:47:23

标签: php function undefined call instagram-api

首先,我检查了数十个搜索结果,其中包括有关该主题的两篇StackOverflow文章-不,似乎没有人回答过这个问题(即使问题本身似乎与某些问题类似)您)

总结问题:当从类中调用公共函数/调用方法时,出现以下错误:“调用未定义函数...”

<?php



use InstagramAPI\Exception\ChallengeRequiredException;
use InstagramAPI\Instagram;
use InstagramAPI\Response\LoginResponse;

use InstagramAPI\Exception\RequestHeadersTooLargeException;
use InstagramAPI\Exception\ThrottledException;
use InstagramAPI\Utils;

require_once __DIR__ . '/vendor/autoload.php';


$username = "name";
$password = "password";

$ig = new \InstagramAPI\Instagram();
    try {
        $ig->login($username, $password);
    } catch (\Exception $e) {
        echo 'Something went wrong: '.$e->getMessage()."\n";
        exit(0);
    }

class RequestCollection
{
    /** @var Instagram The parent class instance we belong to. */
    public $ig;
    /**
     * Constructor.
     *
     * @param Instagram $parent The parent class instance we belong to.
     */
    public function __construct(
        $parent)
    {
        $this->ig = $parent;
    }
    /**
     * Paginate the request by given exclusion list.
     *
     * @param Request     $request     The request to paginate.
     * @param array       $excludeList Array of numerical entity IDs (ie "4021088339")
     *                                 to exclude from the response, allowing you to skip entities
     *                                 from a previous call to get more results.
     * @param string|null $rankToken   The rank token from the previous page's response.
     * @param int         $limit       Limit the number of results per page.
     *
     * @throws \InvalidArgumentException
     *
     * @return Request
     */
    protected function _paginateWithExclusion(
        Request $request,
        array $excludeList = [],
        $rankToken = null,
        $limit = 30)
    {
        if (!count($excludeList)) {
            return $request->addParam('count', (string) $limit);
        }
        if ($rankToken === null) {
            throw new \InvalidArgumentException('You must supply the rank token for the pagination.');
        }
        Utils::throwIfInvalidRankToken($rankToken);
        return $request
            ->addParam('count', (string) $limit)
            ->addParam('exclude_list', '['.implode(', ', $excludeList).']')
            ->addParam('rank_token', $rankToken);
    }
    /**
     * Paginate the request by given multi-exclusion list.
     *
     * @param Request     $request     The request to paginate.
     * @param array       $excludeList Array of grouped numerical entity IDs (ie "users" => ["4021088339"])
     *                                 to exclude from the response, allowing you to skip entities
     *                                 from a previous call to get more results.
     * @param string|null $rankToken   The rank token from the previous page's response.
     * @param int         $limit       Limit the number of results per page.
     *
     * @throws \InvalidArgumentException
     *
     * @return Request
     */
    protected function _paginateWithMultiExclusion(
        Request $request,
        array $excludeList = [],
        $rankToken = null,
        $limit = 30)
    {
        if (!count($excludeList)) {
            return $request->addParam('count', (string) $limit);
        }
        if ($rankToken === null) {
            throw new \InvalidArgumentException('You must supply the rank token for the pagination.');
        }
        Utils::throwIfInvalidRankToken($rankToken);
        $exclude = [];
        $totalCount = 0;
        foreach ($excludeList as $group => $ids) {
            $totalCount += count($ids);
            $exclude[] = "\"{$group}\":[".implode(', ', $ids).']';
        }
        return $request
            ->addParam('count', (string) $limit)
            ->addParam('exclude_list', '{'.implode(',', $exclude).'}')
            ->addParam('rank_token', $rankToken);
    }
}


class People extends RequestCollection
{


    public function getInfoByName(
        $username,
        $module = 'feed_timeline')
    {
        return $this->ig->request("users/{$username}/usernameinfo/")
            ->addParam('from_module', $module)
            ->getResponse(new Response\UserInfoResponse());
    }

}

getInfoByName("testuser")
//echo setCloseFriends(["Versaute.Witze", "Instagram"], ["leonie.kai"]);

//$ig->people->setCloseFriends($add = $addinput, $remove = $removeinput, $module = 'favorites_home_list', $source = 'audience_manager');

?>

问题出在“ getInfoByName”函数之内-显然无法调用。 我指的GitHub代表是mgp25 / Instagram-API。

1 个答案:

答案 0 :(得分:0)

您必须初始化一个类的新实例。

(new People($ig))->getInfoByName('testuser')