M
M
Mitya ToDaSyo2018-12-09 03:42:16
PHP
Mitya ToDaSyo, 2018-12-09 03:42:16

VK api SDK problem with plug-in function addresses, how to solve?

I connected the VK api SDK, it was convenient at first sight, but I ran into a problem!
According to the idea, I just needed to include autoload.php and enjoy the finished solution.
As a result, it turned out that the functions are not loaded automatically and in order to use the SDK in each file, for each function and / or class, you need to sculpt a third leg.
It should be:

$vk = new VKApiClient(VER);
            $oauth          =  new VKOAuth(); 
            $client_id      =  API_CLIENT_ID; 
            $redirect_uri =  REDIR; 
            $display        =  VKOAuthDisplay::PAGE; 
            $scope          =  array(VKOAuthUserScope::WALL, 
                                     VKOAuthUserScope::GROUPS, 
                                     VKOAuthUserScope::EMAIL, 
                                     VKOAuthUserScope::STATS, 
                                     VKOAuthUserScope::OFFLINE
                                  );
            $browser_url = $oauth->getAuthorizeUrl(VKOAuthResponseType::CODE, $client_id, $redirect_uri, $display, $scope, $state);

But in order for it to work, you have to do this
$vk = new \VK\Client\VKApiClient(VER);
            $oauth         =  new \VK\OAuth\VKOAuth(); 
            $client_id     =  API_CLIENT_ID; 
            $redirect_uri  =  REDIR; 
            $display       =  \VK\OAuth\VKOAuthDisplay::PAGE; 
            $scope         =  array(\VK\OAuth\Scopes\VKOAuthUserScope::WALL, 
                                    \VK\OAuth\Scopes\VKOAuthUserScope::GROUPS, 
                                    \VK\OAuth\Scopes\VKOAuthUserScope::EMAIL, 
                                    \VK\OAuth\Scopes\VKOAuthUserScope::STATS, 
                                    \VK\OAuth\Scopes\VKOAuthUserScope::OFFLINE
                                );
            $browser_url = $oauth->getAuthorizeUrl(\VK\OAuth\VKOAuthResponseType::CODE, $client_id, $redirect_uri, $display, $scope, $state);

Or so
use \VK\OAuth\VKOAuth;
use \VK\OAuth\ResponseType;
use \VK\Exceptions\VKClientException;
use \VK\Exceptions\VKOAuthException;
use \VK\OAuth\Scope\VKOAuthUserScope;
...
...

$vk = new VKApiClient(VER);
            $oauth          =  new VKOAuth(); 
            $client_id      =  API_CLIENT_ID; 
            $redirect_uri =  REDIR; 
            $display        =  VKOAuthDisplay::PAGE; 
            $scope          =  array(VKOAuthUserScope::WALL, 
                                     VKOAuthUserScope::GROUPS, 
                                     VKOAuthUserScope::EMAIL, 
                                     VKOAuthUserScope::STATS, 
                                     VKOAuthUserScope::OFFLINE
                                  );
            $browser_url = $oauth->getAuthorizeUrl(VKOAuthResponseType::CODE, $client_id, $redirect_uri, $display, $scope, $state);

And everything would be fine, but there are quite a lot of them, and if you don’t connect one, you immediately get an error 500 ... At the same time, I still don’t know how to correctly write the path to the functions in this case (for Users() and get(), the diagram above does not play here...):
$UserInfo  = $vk->Users()->get($UserToken['access_token'], array(
    'user_ids'  =>  $UserToken['user_id'], 
    'access_token' =>  $UserToken['access_token'], 
    ));

I beg you to give a little of your precious time and share your wisdom.
Perhaps a solution on the surface, I just don’t see it because of my little knowledge ...
PS: also among the SDK files, I came across such a class as, for example, GenerateActions, trying to find out what it is and what they eat with, I went to smoke the manual, but there about it's nothing, nothing at all. And in general, everything that I found on the net on the issue of working with the SDK is either the simplest in the form of authorization, or immediately complex. It feels like reading a book before - today we will start learning to program - echo "Hello world"; will display a message ... And now let's take a more complicated example and immediately pour so much information on you ...
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mitya ToDaSyo, 2018-12-18
@dimastik1986

VK themselves don't know anything))
5c18334a536f0585772894.jpeg

A
Artem, 2018-12-09
@proudmore

If we are talking about the scope parameter, which needs to be collected manually, then this is intended, since this is a set of access rights that will be available for your Oauth session.
In the same way, as for a large number of connections, it's time to write a class that will do it itself every time it is needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question