Answer the question
In order to leave comments, you need to log in
VK api SDK installation and connection, how to do it right?
I can’t get to the bottom of it ... Today, for the first time in my life, I installed something on the site with git through the terminal ...
I decided to inquire about how the VK api SDK works, but I couldn’t even connect it))))
There is little information on the network, in the instructions not a word about it ...
In which folder should the SDK be installed? in public_html?
As I understand it, you can connect autoload.php and then functions, but will it pull up the necessary files on its own?
Thank you!
Answer the question
In order to leave comments, you need to log in
Here is a working version, the problem was that you cannot use classes that are not in the same namespace as the current script.
require_once __DIR__.'/vendor/autoload.php';
use \VK\Client\VKApiClient;
use \VK\OAuth\VKOAuth;
use \VK\OAuth\VKOAuthDisplay;
use \VK\OAuth\Scopes\VKOAuthUserScope;
use \VK\OAuth\VKOAuthResponseType;
$vk = new VKApiClient(VER);
$oauth = new VKOAuth();
$client_id = API_CLIENT_ID;
$redirect_uri = REDIR;
$display = VKOAuthDisplay::PAGE;
$scope = array(VKOAuthUserScope::WALL, VKOAuthUserScope::GROUPS);
$state = 'secret_state_code';
$browser_url = $oauth->getAuthorizeUrl(VKOAuthResponseType::CODE, $client_id, $redirect_uri, $display, $scope, $state);
print $browser_url;
It's time to discover the wonderful world of package managers!
1. First, install composer: https://getcomposer.org/doc/00-intro.md
2. Following the instructions ( https://github.com/VKCOM/vk-php-sdk), write in the project folder: composer require vkcom/vk-php-sdk
3. You will have composer.json, composer.lock files and a vendor folder.
3. Create index.php next to them and include the packages installed via composer:
<?php
require __DIR__ . '/vendor/autoload.php';
// теперь можем работать с VK API
$vk = new VK\Client\VKApiClient();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question