A
A
Alexey Korolev2020-11-08 16:58:51
PHP
Alexey Korolev, 2020-11-08 16:58:51

Why doesn't the output of images work in the posting script on the social network?

I want to make automatic posting shortstory VK (DLE). A friend helped write part of the code, but the code itself cannot display VK media, it only posts text. Help someone who can fix at least a bug due to which it does not display VK pictures, and if it's not difficult, then finish the script.

<?php
   

            // Need to have the vk.php in the same directory.
            include 'vk.php';
        
            // Please complete the below with your details/credentials.
            $config['secret_key'] = 'ключ';
            $config['client_id'] = '-7647836';
            $config['user_id'] = '-185764440';
            $config['access_token'] = 'токен';
            $config['scope'] = 'wall,photos,friends,groups';
        
            // Get a new instance of VK.
            $v = new Vk($config);
        
            // Define the attachment to insert, in this case an image.
            $attachments = $v->upload_photo(0, array('test.jpg'));
        
            // Post the message and image to your wall.
            $response = $v->wall->post(array(
               'message'=>'test 1737759.jpg',
               'attachments' => implode(',', $attachments)
            ));
        
    


            // $curl = curl_init();
            // curl_setopt_array($curl, [
            //     CURLOPT_URL => 'https://api.vk.com/method/wall.post',
            //     CURLOPT_POST => true,
            //     CURLOPT_SSL_VERIFYPEER => false,
            //     CURLOPT_SSL_VERIFYHOST => false,
            //     CURLOPT_RETURNTRANSFER => true,
            //     CURLOPT_POSTFIELDS => [
            //         'owner_id' => '-185764440',
            //         'message' => 'text',
            //         'access_token' => 'токен',
            //         'v' => '5.85',
            //         'attachments'=>'photo'.'66748_265827614'.'http://habrahabr.ru'
            //     ]
            // ]);
            // $response = curl_exec($curl);
            // if ($response === false) {
            //     die('Во время запроса произошла ошибка!'.PHP_EOL.curl_errno($curl).' - '.curl_error($curl));
            // }
            
            // $response = json_decode($response, true);
            // if (isset($response['error'])) {
            //     die('Ошибка VK API!'.PHP_EOL.$response['error']['error_code'].' - '.$response['error']['error_msg']);
            // }
            // curl_close($curl);
            
            // $response = $response['response'];
            // var_dump($response);
?>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question