我是yii的新手,需要调用google的pagespeed API。 当我在浏览器中输入以下内容时:
https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=mysite.com&key=myKey
我得到了我想要的东西,但使用下面的代码:
$client = new Client(['transport' => 'yii\httpclient\CurlTransport']);
$response = $client->createRequest()
->setMethod('get')
->setUrl('https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=mySite.com&key=myKey')
->setOptions([
CURLOPT_VERBOSE=> 1,
CURLOPT_CONNECTTIMEOUT => 100, // connection timeout
CURLOPT_TIMEOUT => 100, // data receiving timeout
])
->send();
echo $response;
我说:
{"error":{"errors":[{"domain":"global","reason":"countryBlocked","message":"This service is not available from Iran. If you believe the country of origin was incorrectly identified, please report it at https://support.google.com/websearch/contact/ip."}],"code":403,"message":"This service is not available from Iran. If you believe the country of origin was incorrectly identified, please report it at https://support.google.com/websearch/contact/ip."}}