我要在Google API之后下载结果-https://developers.google.com/apis-explorer/#p/searchconsole/v1/searchconsole.urlTestingTools.mobileFriendlyTest.run? -输入的网站是否可移动。
我的代码如下:
stat -c $'%U\n%G' /etc/motd
他收到了这样的数据:
<?php
$data="http://holowanie.net/";
$url="https://searchconsole.googleapis.com/v1/urlTestingTools/mobileFriendlyTest:run?fields=mobileFriendliness%2CmobileFriendlyIssues%2CresourceIssues%2Cscreenshot%2CtestStatus&key={myapi}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$payload = json_encode( array( "url"=> $data, "requestScreenshot"=>true ) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$api_content = curl_exec ($ch);
curl_close ($ch);
$api_result = json_decode($api_content,true);
print_r($api_result);
我想使用以下方式致电给他们
Array
(
[testStatus] => Array
(
[status] => COMPLETE
)
[mobileFriendliness] => NOT_MOBILE_FRIENDLY
[mobileFriendlyIssues] => Array
(
[0] => Array
(
[rule] => USE_LEGIBLE_FONT_SIZES
)
[1] => Array
(
[rule] => TAP_TARGETS_TOO_CLOSE
)
[2] => Array
(
[rule] => CONFIGURE_VIEWPORT
)
)
)
但是,它收到这样的错误:
foreach($api_result as $info) {
echo $info['mobileFriendliness'];
echo $info['status'];
}
foreach($api_result as $mobileFriendlyIssues) {
foreach($mobileFriendlyIssues as $mobiles) {
echo $mobiles['rule'];
}
}