google api在通过浏览器调用时返回所需的数据,但在我的应用程序中从curl调用时会出现countryBlocked错误

时间:2017-12-22 20:25:05

标签: php google-api

我是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."}}

0 个答案:

没有答案