Я загружаю результаты после Google API - https://developers.google.com/apis-explorer/#p/searchconsole/v1/searchconsole.urlTestingTools.mobileFriendlyTest.run? - является ли введенный веб-сайт мобильным.
Мой код выглядит так:
<?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'];
}
}
Однако он получает такие ошибки:
Notice: Undefined index: mobileFriendliness in C:\xampp\htdocs\google\index.php on line 41
COMPLETE
Warning: Illegal string offset 'mobileFriendliness' in C:\xampp\htdocs\google\index.php on line 41
N
Warning: Illegal string offset 'status' in C:\xampp\htdocs\google\index.php on line 42
N
Notice: Undefined index: mobileFriendliness in C:\xampp\htdocs\google\index.php on line 41
Notice: Undefined index: status in C:\xampp\htdocs\google\index.php on line 42
Warning: Illegal string offset 'rule' in C:\xampp\htdocs\google\index.php on line 54
C
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\google\index.php on line 53
USE_LEGIBLE_FONT_SIZESTAP_TARGETS_TOO_CLOSESIZE_CONTENT_TO_VIEWPORTCONFIGURE_VIEWPORT