Вот мой рабочий код:
function vk ($vkscript) {
$token = '7afa4204ca81dccc0549e5ee3**********80f9ac76********a1de69d3f4a9d933';
$url = 'https://api.vk.com/method/execute';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('access_token' => $token, 'code' => $vkscript, 'v' => '5.69'));
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
$vkscript = '
var req_params = {
"owner_id" : "-160******",
"from_group" : "1",
"message" : "'.$for_pub['text'].'",
"attachments" : "photo'.$result['response'][0]['owner_id'].'_'.$result['response'][0]['id'].'",
"publish_date" : "'.$publish_date.'",
"v" : "5.69"
};
var result = API.wall.post(req_params);
return result;';
print vk($vkscript );