Created
February 7, 2016 23:45
-
-
Save ko31/6928a9e0b463f0619180 to your computer and use it in GitHub Desktop.
【PageSpeed Insights】APIリクエストのサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// APIキー | |
$key = "Your API Key"; | |
// mobile or desktop | |
$strategy = "mobile"; | |
// URLリスト読み込み | |
$lines = file('url.txt', FILE_IGNORE_NEW_LINES); | |
// URLの分だけAPIリクエストして解析 | |
foreach ($lines as $url) { | |
$api = "https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=".$url."&strategy=".$strategy."&key=".$key; | |
$json = file_get_contents($api); | |
$data = json_decode($json); | |
if ($data->responseCode == 200) { | |
$score = $data->ruleGroups->SPEED->score; | |
} else { | |
$score = "error"; | |
} | |
echo $url.",".$score."\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment