Google Pagespeed v4 worked using "screenshot" to archive our newspaper website daily, until Wednesday this week. I can find no information if they removed support for 'field=screenshot' but it no longer returns JSON. Is there a new method to capture screenshot, or is it gone?
private function capture_thumbnail(){
if(false === $data = file_get_contents('https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=' . $this->url . '&filter_third_party_resources=true&screenshot=true&strategy=desktop&fields=screenshot&key=' . $this->google_server_api_key))
throw new Exception('Could not get url contents');
$data = json_decode($data, true);
if(empty($data['screenshot']['data']))
throw new Exception('Screenshot data empty');
$image = str_replace(
array('_', '-'),
array('/', '+'),
$data['screenshot']['data']
);
$dir = SCREENSHOTS_DIR . date(CAPTURE_DIR_DATE_FORMAT) . '/';
if(false === file_exists($dir)){
if(false === mkdir($dir))
throw new Exception('Could not create screenshot directory');
}
if(false === file_put_contents($dir . date('H') . '.jpg', base64_decode($image)))
throw new Exception('Could not save image');
}
}