I can’t get to the point ... Today for the first time in my life with git I installed something on the site via the terminal ... I decided to ask how the VK api SDK works, but I couldn’t even connect)))) I don’t understand, I tried a lot of options , can not run ...

require __DIR__.'/vendor/autoload.php'; $vk = new \VK\Client\VKApiClient('5.92'); $oauth = new \VK\OAuth\VKOAuth(); $client_id = API_CLIENT_ID; $redirect_uri = 'http://site.ru/index.php'; $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); 

Fatal error: Uncaught Error: Class 'VKOAuthDisplay' not found

    2 answers 2

    The reasons are that you are trying to use classes that are not in the same namespace with the current script. Use use , or write all the paths completely, for example:

     $display = \VK\OAuth\VKOAuthDisplay::PAGE; 

    This same path can be found in the class itself, which is called. It follows the word namespace. The above variant implies an indication of the paths at the beginning of the class using use . But you can specify as in the example above.

    • Thank you very much! I was already upset and took this prikolyuhu)) But after your answer, I installed it and everything turned out) Now the question is, this is not very convenient) You can live of course, but how many extra characters in the code will be ... - Dimastik86

    Who needs it, that's what happened ... Thank you Eddir!

     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;