InstagramScraper\Instagram::getLocationTopMediasById PHP Method

getLocationTopMediasById() public static method

public static getLocationTopMediasById ( $facebookLocationId )
    public static function getLocationTopMediasById($facebookLocationId)
    {
        $response = Request::get(Endpoints::getMediasJsonByLocationIdLink($facebookLocationId));
        if ($response->code === 404) {
            throw new InstagramNotFoundException('Location with this id doesn\'t exist');
        }
        if ($response->code !== 200) {
            throw new InstagramException('Response code is ' . $response->code . '. Body: ' . $response->body . ' Something went wrong. Please report issue.');
        }
        $jsonResponse = json_decode($response->raw_body, true);
        $nodes = $jsonResponse['location']['top_posts']['nodes'];
        $medias = [];
        foreach ($nodes as $mediaArray) {
            $medias[] = Media::fromTagPage($mediaArray);
        }
        return $medias;
    }

Usage Example

 public function testGetLocationTopMediasById()
 {
     $medias = Instagram::getLocationTopMediasById(1);
     $this->assertEquals(9, count($medias));
 }