public static function getLastLikesByCode($code) { $response = Request::get(Endpoints::getLastLikesByCodeLink($code)); if ($response->code === 404) { throw new InstagramNotFoundException('Media with this shortcode 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); $users = []; foreach ($jsonResponse['likes']['nodes'] as $userArray) { $users[] = Account::fromAccountPage($userArray['user']); } return $users; }
public static function fromMediaPage($mediaArray) { $instance = new self(); $instance->id = $mediaArray['id']; $instance->type = 'image'; if ($mediaArray['is_video']) { $instance->type = 'video'; $instance->videoStandardResolutionUrl = $mediaArray['video_url']; $instance->videoViews = $mediaArray['video_views']; } if (isset($mediaArray['caption_is_edited'])) { $instance->captionIsEdited = $mediaArray['caption_is_edited']; } if (isset($mediaArray['is_ad'])) { $instance->isAd = $mediaArray['is_ad']; } $instance->createdTime = $mediaArray['date']; $instance->code = $mediaArray['code']; $instance->link = Endpoints::getMediaPageLink($instance->code); $instance->commentsCount = $mediaArray['comments']['count']; $instance->likesCount = $mediaArray['likes']['count']; $images = self::getImageUrls($mediaArray['display_src']); $instance->imageStandardResolutionUrl = $images['standard']; $instance->imageLowResolutionUrl = $images['low']; $instance->imageHighResolutionUrl = $images['high']; $instance->imageThumbnailUrl = $images['thumbnail']; if (isset($mediaArray['caption'])) { $instance->caption = $mediaArray['caption']; } if (isset($mediaArray['location']['id'])) { $instance->locationId = $mediaArray['location']['id']; } if (isset($mediaArray['location']['name'])) { $instance->locationName = $mediaArray['location']['name']; } $instance->owner = Account::fromMediaPage($mediaArray['owner']); return $instance; }