V
V
Vitaly2019-06-25 11:40:33
PHP
Vitaly, 2019-06-25 11:40:33

How to publish several photos with a description on the VK wall?

I use the photos.saveWallPhoto method, the docs say that no more than 6 photos can be passed for the photo parameter in one method, the caption parameter is a string, if I pass a value to caption, it is the same for all photos.
The question is how to publish a gallery of several photos with its own description for each photo?

// создание массива из 6 фото
                        $arrImg = array();
      foreach ($photo as $key => $img) {
        $key++;
        $arrImg['file'.$key] = new CURLFile($_SERVER["DOCUMENT_ROOT"].$img['img']);
      } 
     
      // Отправка изображений на сервер.
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $res->response->upload_url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $arrImg);


      $res = json_decode(curl_exec($ch));
      curl_close($ch);

      if (!empty($res->server)) {
      	// Сохранение фото в группе.
          $params = array(
            'group_id' =>$group_id,
            'server' =>$res->server,
            'photo' =>stripslashes($res->photo),
            'hash' =>$res->hash,
            'caption' =>$capt,
            'access_token' => $token,
            'v'            => '5.95' 
          );
          // Отправить сообщение
          $ch=curl_init();
          curl_setopt($ch, CURLOPT_URL,'https://api.vk.com/method/photos.saveWallPhoto?');
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_POST, 1);
          curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));

          $res = json_decode(curl_exec($ch));
          curl_close($ch);

      	$attach = array();
      	foreach ($res->response as $key => $photo) {
      		$attach[$key] = 'photo' . $photo->owner_id . '_' . $photo->id; 
      	} 
        $attach = implode(',', $attach);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lightmanLP, 2019-06-27
@lightmanLP

Sending multiple different requests is not an option?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question