[英]How to fix 'Call for undefined function' - PHP, mgp25
首先,我检查了几十个搜索结果,包括几篇关于这个主题的 StackOverflow 文章——不,似乎没有人回答过这个问题(尽管这个问题本身可能与你们中的一些人相似)
总结问题:当从class/调用方法中调用公共function时,出现以下错误:'Call to undefined function...'
<?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”function - 显然无法调用。 我指的 GitHub 代表是 mgp25/Instagram-API。
您必须初始化 class 的新实例。
(new People($ig))->getInfoByName('testuser')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.