PHP code example of kristobaljunta / vkontakte-wall-posting

1. Go to this page and download the library: Download kristobaljunta/vkontakte-wall-posting library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kristobaljunta / vkontakte-wall-posting example snippets




use KristobalJunta\Vkontakte;

$accessToken = 'your access token';
$publicID = 'your public ID here';
$vkAPI = new Vkontakte(['access_token' => $accessToken]);

$attachments = [
    'images' => [
        # attaching image by url
        [
            'type' => 'image',
            'url' => 'image-link'
        ],
        # attaching image by full file path
        [
            'type' => 'image',
            'path' => '/full/path/to/image'
        ]
    ]
    # attaching link (there can be only one)
    'link' => 'link-url'
];

if ($vkAPI->postToPublic($publicID, "Hello world", $attachments, ['#вконтакте api', '#автопостинг', '#первые шаги'])) {
    echo "Yeah, success!\n";
} else {
    echo "Error publishing post\n";
}