Saturday, 15 February 2014

How to use the JSON data via PHP from Google Insight API -



How to use the JSON data via PHP from Google Insight API -

i utilize info google insight api via php page. (here documentation)

for example, how utilize "numberjsresources" returned google insight ?

$jsonstring = curl "https://www.googleapis.com/pagespeedonline/v1/runpagespeed?url=http://code.google.com/speed/page-speed/&key=myapikey"; $obj = json_decode($jsonstring); echo $obj->responsecode;

you using curl wrongly.

$ch = curl_init("https://www.googleapis.com/pagespeedonline/v1/runpagespeed?url=http://code.google.com/speed/page-speed/&key=myapikey"); curl_setopt($ch, curlopt_returntransfer, 1); $res = curl_exec($ch); $obj = json_decode($res, true); echo $obj['pagestats']['numberjsresources'];

manual : http://www.php.net/manual/en/book.curl.php

php json google-api

No comments:

Post a Comment