public static function getMediaByUrl($mediaUrl)
{
if (filter_var($mediaUrl, FILTER_VALIDATE_URL) === false) {
throw new \InvalidArgumentException('Malformed media url');
}
$response = Request::get(rtrim($mediaUrl, '/') . '/?__a=1');
if ($response->code === 404) {
throw new InstagramNotFoundException('Media with given code does not exist or account is private.');
}
if ($response->code !== 200) {
throw new InstagramException('Response code is ' . $response->code . '. Body: ' . $response->body . ' Something went wrong. Please report issue.');
}
$mediaArray = json_decode($response->raw_body, true);
if (!isset($mediaArray['media'])) {
throw new InstagramException('Media with this code does not exist');
}
return Media::fromMediaPage($mediaArray['media']);
}