A
A
Anton Titov2018-05-17 04:17:36
PHP
Anton Titov, 2018-05-17 04:17:36

Is it possible to enter multiple values ​​into a variable in this php script?

There is a php script that publishes posts in open communities using the wall.post method.
$group_id contains the ID of the group in which the entry is to be placed. Is it possible somehow to add multiple identifiers to a given variable? I would like to publish posts in several communities with one execution of the script.
Description of the wall.post method

/*
VK-API WALL.POST Отправляем запись в группу методом post, через CURL
*/
$group_id ='-1';
$token = file_get_contents('token.txt');
$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"   => 0,
    "message"      => $text,
    "access_token" => $token,
    "v"            => '5.74',

),
  CURLOPT_URL => $url,
));
$query = curl_exec($ch);
curl_close($ch);
if(!$query){
  printf('Ошибка. Пост не опубликован!');
  exit;
}
else{
  printf('Пост успешно опубликован!');
  exit;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2018-05-17
@fubarblg

wall.post()publishes a single entry.
For industrial-scale acceleration of spam, there is an option with the execute() method , which can wrap up to 25 calls to the VKontakte API.
Those. on the server, you collect some JavaScript-like code into a string, something like:

var params = {
  "message": "Текст поста",
  "from_group": 0,
};
var out = { "result": [] };

params.owner_id = 10101; // первая группа
params.guid = 'abrakadabra';
out.result.push( API.wall.post(data));

params.owner_id = 20202; // вторая группа
params.guid = 'drugayaabrakadabra';
out.result.push( API.wall.post(data));
// ...
params.owner_id = 2500025; // 25-я группа
params.guid = 'uniqueabrakadabra';
out.result.push( API.wall.post(data));

return out;

And send this code as text as a parameter codein the methodexecute()

S
Sergey Gerasimov, 2018-05-17
@mrTeo

This cannot be done with a single request. Owner_id must be an integer, i.e. contain only 1 value. Otherwise, it throws an error "error_msg": "One of the parameters specified was missing or invalid: owner_id not integer" Solved
using multiple queries in a loop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question