InstagramScraper\Instagram::getPaginateMediasByTag PHP Метод

getPaginateMediasByTag() публичный статический Метод

public static getPaginateMediasByTag ( $tag, $maxId = '' )
    public static function getPaginateMediasByTag($tag, $maxId = '')
    {
        $hasNextPage = true;
        $medias = [];
        $toReturn = ['medias' => $medias, 'maxId' => $maxId, 'hasNextPage' => $hasNextPage];
        $response = Request::get(Endpoints::getMediasJsonByTagLink($tag, $maxId));
        if ($response->code !== 200) {
            throw new InstagramException('Response code is ' . $response->code . '. Body: ' . $response->body . ' Something went wrong. Please report issue.');
        }
        $arr = json_decode($response->raw_body, true);
        if (!is_array($arr)) {
            throw new InstagramException('Response decoding failed. Returned data corrupted or this library outdated. Please report issue');
        }
        if (count($arr['tag']['media']['count']) === 0) {
            return $toReturn;
        }
        $nodes = $arr['tag']['media']['nodes'];
        if (count($nodes) == 0) {
            return $toReturn;
        }
        foreach ($nodes as $mediaArray) {
            $medias[] = Media::fromTagPage($mediaArray);
        }
        $maxId = $arr['tag']['media']['page_info']['end_cursor'];
        $hasNextPage = $arr['tag']['media']['page_info']['has_next_page'];
        $toReturn = ['medias' => $medias, 'maxId' => $maxId, 'hasNextPage' => $hasNextPage];
        return $toReturn;
    }