function request($url) {
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, ['Authorization: OAuth AQAAAAAEaSNLAAULMOLNp8fdYEuukqx4-TmHnCQ']);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handle);
if (curl_getinfo($handle, CURLINFO_HTTP_CODE) == 200) {
return json_decode($response);
}
return null;
}
$user = request('https://api.webmaster.yandex.net/v3/user/');
if ($user) {
$sites = request('https://api.webmaster.yandex.net/v3/user/'.$user->user_id.'/hosts/');
if ($sites) {
foreach ($sites->hosts as $host) {
echo $host->unicode_host_url."<br/>";
}
}
}
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, 'https://api.webmaster.yandex.net/v3/user/');
curl_setopt($handle, CURLOPT_HTTPHEADER, ['Authorization: OAuth AQAAAAAEaSNLAAULMOLNp8fdYEuukqx4-TmHnCQ']);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handle);
var_dump($response); #string(20) "{"user_id":73999179}"
$model->body_.$lang = implode($body);
Это неверная конструкция)