public function login()
 {
     require_once dirname(__FILE__) . '/../VK.php';
     // require_once('/VKException.php');
     $vk_config = array('app_id' => $_ENV['VK_APP_ID'], 'api_secret' => $_ENV['VK_API_SECRET'], 'callback_url' => $_ENV['VK_CALLBACK_URI'], 'api_settings' => $_ENV['API_SETTINGS']);
     $vk = new VK\VK($vk_config['app_id'], $vk_config['api_secret']);
     if (!isset($_REQUEST['code'])) {
         /**
          * If you need switch the application in test mode,
          * add another parameter "true". Default value "false"
          * Ex $vk->getAuthorizeURL($api_settings, $callback_url, true);
          */
         $authorize_url = $vk->getAuthorizeURL($vk_config['api_settings'], $vk_config['callback_url']);
         echo '<a href="' . $authorize_url . '">Sign in with VK</a>';
     } else {
         $access_token = $vk->getAccessToken($_REQUEST['code'], $vk_config['callback_url']);
         echo 'access token: ' . $access_token['access_token'] . '<br />expires: ' . $access_token['expires_in'] . ' sec.' . '<br />user id: ' . $access_token['user_id'] . '<br /><br />';
         $user_friends = $vk->api('friends.get', array('uid' => '12345', 'fields' => 'uid,first_name,last_name', 'order' => 'name'));
         foreach ($user_friends['response'] as $key => $value) {
             echo $value['first_name'] . ' ' . $value['last_name'] . ' (' . $value['uid'] . ')<br />';
         }
     }
 }
Beispiel #2
0
<?php

require 'src/VK/VK.php';
$appId = "5153763";
$userId = "334151636";
$secretCode = "XftZbIGFnYEpJImOnEH0";
$code = "8ee64dc9a62b65d6e8";
$redirectUri = "https://itprom.ru/vk/index001.php";
$redirectUri = "https://oauth.vk.com/blank.html";
$accessToken = "a8bd1eda7c5dc82d227ce03a1f9e3c42c873d84f1796d83719390d046d930b16e2c9672422a0d8fb363c3";
$vk = new \VK\VK($appId, $secretCode, $accessToken);
print_r($vk->getAccessToken('360f95056bc83f9b87'));
//$authUrl = $vk->getAuthorizeUrl('photos,wall,offline');
//$wallPostResult = $vk->api("wall.post", array(
//    'owner_id' => $userId,
//    'message' => "Ваалейкум салам"
//));
//print_r($wallPostResult);
?>

<div>
    <a href="">Auth</a>
</div>
Beispiel #3
0
<?php 
/**
 * Example 2.
 * Get access token via OAuth and usage VK API.
 * @link http://vk.com/developers.php VK API
 */
error_reporting(E_ALL);
require_once '../src/VK/VK.php';
require_once '../src/VK/VKException.php';
$vk_config = array('app_id' => '{YOUR_APP_ID}', 'api_secret' => '{YOUR_API_SECRET}', 'callback_url' => 'http://{YOUR_DOMAIN}/samples/example-2.php', 'api_settings' => '{ACCESS_RIGHTS_THROUGH_COMMA}');
try {
    $vk = new VK\VK($vk_config['app_id'], $vk_config['api_secret']);
    if (!isset($_REQUEST['code'])) {
        /**
         * If you need switch the application in test mode,
         * add another parameter "true". Default value "false".
         * Ex. $vk->getAuthorizeURL($api_settings, $callback_url, true);
         */
        $authorize_url = $vk->getAuthorizeURL($vk_config['api_settings'], $vk_config['callback_url']);
        echo '<a href="' . $authorize_url . '">Sign in with VK</a>';
    } else {
        $access_token = $vk->getAccessToken($_REQUEST['code'], $vk_config['callback_url']);
        echo 'access token: ' . $access_token['access_token'] . '<br />expires: ' . $access_token['expires_in'] . ' sec.' . '<br />user id: ' . $access_token['user_id'] . '<br /><br />';
        $user_friends = $vk->api('friends.get', array('uid' => '12345', 'fields' => 'uid,first_name,last_name', 'order' => 'name'));
        foreach ($user_friends['response'] as $key => $value) {
            echo $value['first_name'] . ' ' . $value['last_name'] . ' (' . $value['uid'] . ')<br />';
        }
    }
} catch (VK\VKException $error) {
    echo $error->getMessage();
}