-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.php
42 lines (30 loc) · 1.22 KB
/
parser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
require 'config.php';
require 'vendor/autoload.php';
$guzzleclient = new \GuzzleHttp\Client([
'timeout' => 60,
'verify' => false,
]);
//Build the API url and request
//https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=https%3A%2F%2Fwww.yourdomain.com&strategy=desktop&fields=formattedResults%2Cid%2CinvalidRules%2Ckind%2CpageStats%2CresponseCode%2CruleGroups%2Cscreenshot%2Ctitle%2Cversion&key={YOUR_API_KEY}
//change this to your url
$urltocheck = "https://www.yourdomain.com";
$psiurl = "https://www.googleapis.com/pagespeedonline/v2/runPagespeed?";
$psivariables = array();
$psivariables[] = "url=".urlencode($urltocheck);
$psivariables[] = "strategy=".urlencode(PSISTRATEGY);
$psivariables[] = "locale=".urlencode(PSILOCALE);
$psivariables[] = "fields=".urlencode(PSIFIELDS);
$psivariables[] = "key=".urlencode(PSIAPIKEY);
if(PSIFILTER_THIRD_PARTY_RESOURCES === true){
$psivariables[] = "filter_third_party_resources=true";
}
if(PSISCREENSHOT === true){
$psivariables[] = "screenshot=true";
}
$psiurl .= implode("&",$psivariables);
//$res is in json format
$res = $client->request('GET', $psiurl);
$jsonobject = json_decode($res->getBody());
//Do what you want with the results
print_r($jsonobject);