1. Go to this page and download the library: Download ufee/vk-api 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/ */
ufee / vk-api example snippets
$vk = getjump\Vk\Core::getInstance()->apiVersion('5.5')->setToken(>>> HERE YOUR TOKENS GOES <<<);
$vk = getjump\Vk\Core::getInstance()->apiVersion('5.5');
$auth = getjump\Vk\Auth::getInstance();
$auth->setAppId('3470411')->setScope('SCOPE')->setSecret('SECRET CODE')->setRedirectUri('http://localhost/test.php'); // SETTING ENV
$token=$auth->startCallback(); // Here we will have token, if everything okay
printf("<a href='%s' target='_top'>LINK</a>", $auth->getUrl());
if($token) {
$vk->setToken($token);
$vk->request('users.get', ['user_ids' => range(1, 100)])->each(function($i, $v) {
if($v->last_name == '') return;
print $v->last_name . '<br>';
});
}
// Long pooling loop
$lp = new getjump\Vk\Wrapper\LongPoll($vk);
$lp->doLoop();
//KISS
$user=new getjump\Vk\Wrapper\User(getjump\Vk\Core::getInstance()->apiVersion('5.5'));
$user->get(1, 'photo_max_orig, sex'); //It will contain RequestTransaction, and will wait for your action, like getting response ->response or calling ->each(callback)
//Since __get and __call are overrided, we will request for a data, only when it neeeded
// Friends gets
$friends = new getjump\Vk\Wrapper\Friends($vk);
foreach($friends->get(15157875, 'first_name, last_name')->batch(100) as $f) //BATCH MEAN $f WILL CONTAIN JUST 100 ELEMENTS, AND REQUEST WILL MADE FOR 100 ELEMENTS
{
/**
* @var $f \getjump\Vk\ApiResponse;
*/
$f->response->each(function($i, $j) {
if(!$j->online) return;
print $j->getName() . '<br>';
});
}
//SECOND OPTION TO JUST GET EVERYTHING, WITHOUT count BEING SEND
$friends->get(15157875, 'first_name, last_name')->response->each(function($i, $d) {
if($d->online)
{
print $d->getName() . '<br>';
}
});
$js1 = $vk->request('messages.get', ['count' => 200, 'offset' =>0 * 200])->toJs(); //IT WILL RETURN VkJs object
$js2 = $vk->request('messages.get', ['count' => 200, 'offset' =>1 * 200])->toJs();
$js3 = $vk->request('messages.get', ['count' => 200, 'offset' =>2 * 200])->toJs();
$js4 = $vk->request('messages.get', ['count' => 200, 'offset' =>3 * 200])->toJs();
$js1
->append($js2) // WE ARE APPENDING js2 to js1
->append($js3)
->append($js4)
->execute() // WE WANT EXECUTE THIS (actually it will return RequestTransaction)
->response //AS FOR NOW WE REALLY DO SOME REQUEST TO API
->each(
function($i, $v) //FIRST CALLBACK IS NEEDED TO GO FOR EVERY PART OF RESPONSE, ARRAY WITH 4-ELS IN OUR CASE
{
$v->each(function($c, $d) { // SECOND TO CHECK EVERY ELEMENTS IN ARRAY WITH 200 ELEMENTS
if(isset($d->body)) print $d->body; //WE JUST OUTPUTTING MESSAGE IF IT SET
});
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.