ufee/vk-api
Composer 安装命令:
composer require ufee/vk-api
包简介
Library for work with API Vk.com
关键字:
README 文档
README
Fork from getjump/vk
That library will help you organize your work with API Vk.com
Installation
You can get library and all of it dependencies through composer
composer require ufee/vk-api
Explanation
Okay, that is how we can instantiate main object for our future requests
$vk = getjump\Vk\Core::getInstance()->apiVersion('5.5')->setToken(>>> HERE YOUR TOKENS GOES <<<);
YOU CAN GET SOME TOKENS AT : You can get some tokens at: http://oauth.vk.com/authorize?client_id=3470411&scope=messages,photos,groups,status,wall,offline&redirect_uri=blank.html&display=page&v=5.5&response_type=token I can't steal them, since it's VK side stuff guys, scope means what rights you needed for, i recommend as much as you can, if you don't want problems. If you wanna use site authorization, look at next snippet:
$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>'; }); }
I already did some wrappers just for you, if you wanna more, please do and pull request but you still can don't use them, or use something like this.
$vk->request('friends.get', ['user_id' => '15157875'])->each(function($i, $v) {});
That us long polling shiet, it works like a hell, as fast as you can see.
// Long pooling loop $lp = new getjump\Vk\Wrapper\LongPoll($vk); $lp->doLoop();
We will do badass stuff, like kiss. You can do like the following and it will works
//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
We can use my own sakhalin technilogies and take all the stuff that VK have for that request using generators
// 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>'; }); }
But you still can do old style stuff
//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>'; } });
That snippet will show you your last 200 messages
//MESSAGES $data = $vk->request('messages.get', ['count' => 200]); $userMap = []; $userCache = []; $user = new \getjump\Vk\Wrapper\User($vk); $fetchData = function($id) use($user, &$userMap, &$userCache) { if(!isset($userMap[$id])) { $userMap[$id] = sizeof($userCache); $userCache[] = $user->get($id)->response->get(); } return $userCache[$userMap[$id]]; }; //REQUEST WILL ISSUE JUST HERE! SINCE __get overrided $data->each(function($key, $value) use($fetchData) { $user = $fetchData($value->user_id); printf("[%s] %s <br>", $user->getName(), $value->body); return; });
Once more black magic. VK has method called execute, that can take something like JS code. Look what i've done for that.
$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 }); });
ufee/vk-api 适用场景与选型建议
ufee/vk-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 52 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 07 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「vkontakte」 「vk」 「vk.com」 「вконтакте」 「вк」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ufee/vk-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ufee/vk-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ufee/vk-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Vkontakte PHP SDK
Library that obtains VK tokens that work for VK audio API. Библиотека для получения токена VK, подходящего для Audio API.
Расширенная работа с API VK
Check request signature for vk.com/dev/vk_apps_docs
VK PHP SDK
Api client for vk.com
统计信息
- 总下载量: 52
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-29