我一直在試圖從API檢索截圖,但是當我解碼圖像並保存它時,我得到一個破碎的圖像。以下是我正在使用的代碼。如果您想測試它,我創建了一個包含谷歌響應的示例文件的tinyurl。谷歌PageSpeed Insights API截圖到文件
$name = 'test';
$result = file_get_contents('http://tinyurl.com/q4smyod');
$result = json_decode($result, true);
$decoded=base64_decode($result['screenshot']['data']);
file_put_contents('img/'.$name.'.jpg',$decoded);
不錯!它完美地工作。謝謝。有沒有可能運行[runpagespeed](https://developers.google.com/speed/docs/insights/v2/reference/pagespeedapi/runpagespeed)來獲得'screenshot.width'和'screenshot.height',而不是默認爲'320px,240px'? – hyip 2016-02-10 14:15:54
非常感謝.. !!完美的工作..! – Ritesh 2016-09-10 11:00:29