<?php
/*
VK-API WALL.POST Отправляем запись в группу методом post, через CURL
*/
$group_id ="-123108209";
$token = "тут мой токен";
$api_ver = "5.74";
$text = file_get_contents('post_data.txt');
$url = sprintf('https://api.vk.com/method/wall.post?');
$ch = curl_init();
curl_setopt_array( $ch, array (
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_POSTFIELDS => array(
"owner_id" => $group_id,
"from_group" => 1,
"Message" => $text,
"access_token" => $token,
"v" => $api_ver,
),
CURLOPT_URL => $url,
));
$query = curl_exec($ch);
curl_close($ch);
if(!$query){
printf('Error');
exit;
}
else{
printf('Success');
exit;
}
printf('Success');
exit;
$decoded = json_decode($query);
if(!$decoded) {
printf("ВК вернул невообразимую фигню: %s", $query);
}
else if( $decoded->error) {
printf("Ошибка %d: %s\n", $decoded->error->error_code, $decoded->error->error_msg);
} else if( $decoded->response) {
printf("Пост опубликован с id %s\n", $decoded->response);
}
exit();
CURLOPT_POSTFIELDS => array( ...
CURLOPT_POSTFIELDS => http_build_query( array( ... ))
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 );