InstagramScraper\Endpoints::getMediasJsonByTagLink PHP Method

    public static function getMediasJsonByTagLink($tag, $maxId = '')
    {
        $url = str_replace('{tag}', urlencode($tag), Endpoints::MEDIA_JSON_BY_TAG);
        return str_replace('{max_id}', urlencode($maxId), $url);
    }

Usage Example

Ejemplo n.º 1
0
 public static function getTopMediasByTagName($tagName)
 {
     $response = Request::get(Endpoints::getMediasJsonByTagLink($tagName, ''));
     if ($response->code === 404) {
         throw new InstagramNotFoundException('Account with given username does not 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);
     $medias = [];
     foreach ($jsonResponse['tag']['top_posts']['nodes'] as $mediaArray) {
         $medias[] = Media::fromTagPage($mediaArray);
     }
     return $medias;
 }