brandembassy/vkontakte-php-sdk

This package is abandoned and no longer maintained. No replacement package was suggested.

Vkontakte PHP SDK

Maintainers

👁 ph-legacy

Package info

github.com/BrandEmbassy/vkontakte-php-sdk

pkg:composer/brandembassy/vkontakte-php-sdk

Statistics

Installs: 104

Dependents: 0

Suggesters: 0

Stars: 0

v2.0.5 2016-06-01 12:53 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 00d656dcb1fb41c529e32db51063987c65f02b5d

phpapioauthsdkvkontaktevk

This package is not auto-updated.

Last update: 2016-08-03 09:14:22 UTC


README

Simple Vkontakte PHP SDK

Install

Install library with composer dependency manager

  • Add "brandembassy-bw/vkontakte-php-sdk": "dev-master" into the require section of your composer.json file
  • Run $ composer.phar install

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="<?php print $vk->getLoginUrl() ?>">Sign In</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();
 $_SESSION['access_token'] = $vk->getAccessToken();
 header('Location: ' . $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
 exit;
} else {
 $vk->setAccessToken($_SESSION['access_token']);
 var_dump($_SESSION);
}

Get the authorized user ID

$userId = $vk->getUserId();

var_dump($userId);

Calling API

$user = $vk->api('users.get', [
 'user_id' => '1',
 'fields' => [
 'photo_50',
 'city',
 'sex',
 ],
]);

var_dump($user);

For more info read the official docs: