bocharsky-bw/vkontakte-php-sdk
最新稳定版本:v2.0.4
Composer 安装命令:
composer require bocharsky-bw/vkontakte-php-sdk
包简介
Vkontakte PHP SDK
README 文档
README
A simple and lightweight PHP SDK library for VKontakte social network.
Install
Install library with Composer dependency manager:
$ composer require bocharsky-bw/vkontakte-php-sdk
Include
Require composer autoloader in your index file:
require __DIR__ . '/path/to/vendor/autoload.php';
Create instance of Vkontakte class with your own configuration parameters:
use \BW\Vkontakte as Vk; $vk = new Vk([ 'client_id' => 'APP_ID', 'client_secret' => 'APP_SECRET', 'redirect_uri' => 'REDIRECT_URI', ]);
OAuth authorization
Build authorization link in your template:
<a href="<?= $vk->getLoginUrl() ?>">Authenticate</a>
Handle response, received from oauth.vk.com and store access token to session
for restore it when page will be reload:
session_start(); // start session if you don't if (isset($_GET['code'])) { $vk->authenticate($_GET['code']); $_SESSION['access_token'] = $vk->getAccessToken(); header('Location: '.'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']); exit; } else { $accessToken = isset($_SESSION['access_token']) ? $_SESSION['access_token'] : null; $vk->setAccessToken($accessToken); var_dump($_SESSION['access_token']); }
Get the authenticated user ID
$userId = $vk->getUserId(); var_dump($userId);
Calling API
/** @var array[] $users */ $users = $vk->api('users.get', [ 'user_id' => 1, 'fields' => [ 'photo_50', 'city', 'sex', ], ]); var_dump($users);
For more info read the official docs:
统计信息
- 总下载量: 58.93k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 33
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-01-24