示例#1
0
function get_photo($id, $aid, $pid)
{
    $vk = new VK\VK(APP_ID, ACCES_CODE);
    $photo = $vk->api('photos.get', array('owner_id' => $id, 'album_id' => $aid, 'photo_ids' => $pid));
    echo '<a href="/albums.php?id=' . $id . '&aid=' . $aid . '"><<< НАЗАД</a><br />';
    if (isset($photo['response']['0']['src_big'])) {
        echo '<img src="' . $photo['response']['0']['src_big'] . '">';
    } else {
        echo "<p>Нет доступа к фотографии...<br> Фотография скрыта настройками приватности :(";
    }
    if (isset($photo['response']['0']['text'])) {
        echo '<p>' . $photo['response']['0']['text'] . '</p>';
    }
}
 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 />';
         }
     }
 }
示例#3
0
<!doctype html>
    <meta charset="utf-8" />
    <style>
    html, body { font-family: monospace; }
    </style>

<?php 
/**
 * Example 3.
 * Usage VK API having access token.
 * @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}', 'access_token' => '{YOUR_ACCESS_TOKEN}');
try {
    $vk = new VK\VK($vk_config['app_id'], $vk_config['api_secret'], $vk_config['access_token']);
    $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();
}
示例#4
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>
示例#5
0
<!doctype html>
    <meta charset="utf-8" />
    <style>
    html, body { font-family: monospace; }
    </style>
    
<?php 
/**
 * Example 1.
 * Usage VK API without authorization.
 * Some calls are not available.
 * @link http://vk.com/developers.php VK API
 */
error_reporting(E_ALL);
require_once '../src/VK/VK.php';
require_once '../src/VK/VKException.php';
try {
    $vk = new VK\VK('{YOUR_APP_ID}', '{YOUR_API_SECRET}');
    // Use your app_id and api_secret
    $users = $vk->api('users.get', array('uids' => '1234,4321', 'fields' => 'first_name,last_name,sex'));
    foreach ($users['response'] as $user) {
        echo $user['first_name'] . ' ' . $user['last_name'] . ' (' . ($user['sex'] == 1 ? 'Girl' : 'Man') . ')<br />';
    }
} catch (VK\VKException $error) {
    echo $error->getMessage();
}
示例#6
0
<?php

$token = '';
$likeFrom = 144953542;
$likeTo = 144953542;
require_once "VK.php";
$APP = ['secretKey' => 'hHbZxrka2uZ6jB1inYsH', 'id' => '2274003'];
$vk = new VK\VK($APP['id'], $APP['secretKey'], $token);
$avatar = $vk->api('photos.get', array('owner_id' => $likeTo, 'album_id' => 'profile', 'count' => 1, 'rev' => 1, 'extended' => 0));
$photo_id = $avatar['response'][0]['pid'];
$dolike = $vk->api('likes.add', array('type' => 'photo', 'owner_id' => $likeTo, 'item_id' => $photo_id));
if ($dolike['response']['likes'] > 0) {
    echo 'success';
}
示例#7
0
<?php

/**
 * Require PHP >= 5.4
 * Search, play and download audio files use VK API.
 * Before downloading files are renamed in the format "%artist% - %title%"
 */
ini_set('default_charset', 'utf-8');
error_reporting(E_ALL);
require_once '../../src/VK/VK.php';
require_once '../../src/VK/VKException.php';
$vk_config = ['app_id' => '{YOUR_APP_ID}', 'api_secret' => '{YOUR_API_SECRET}', 'access_token' => '{YOUR_ACCESS_TOKEN}'];
try {
    $vk = new VK\VK($vk_config['app_id'], $vk_config['api_secret'], $vk_config['access_token']);
    // Rename and download audio file
    if (isset($_GET['download']) && !empty($_GET['download'])) {
        $rs = $vk->api('audio.getById', ['audios' => $_GET['download']]);
        if (isset($rs['response'])) {
            $rs = $rs['response'][0];
            header('Content-Type: application/force-download');
            header('Content-Disposition: attachment; filename="' . $rs['artist'] . ' - ' . $rs['title'] . '.mp3"');
            readfile($rs['url']);
        }
        die;
    } else {
        // Get audio list from query string
        $q = isset($_GET['q']) ? $_GET['q'] : '';
        $rs = [];
        if (!empty($q)) {
            $rs = $vk->api('audio.search', ['v' => '2.0', 'q' => $q]);
        }
示例#8
0
    <style>
    html, body { font-family: monospace; }
    </style>

<?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 />';
        }
示例#9
0
<?php

require_once "../config.php";
require_once "../vk.php";
require_once "../vkexception.php";
$vk_config = array('app_id' => '4798482', 'api_secret' => 'yat6sCVTs6g4D8nCgWSJ', 'access_token' => $config['token']);
try {
    $vk = new VK\VK($vk_config['app_id'], $vk_config['api_secret'], $vk_config['access_token']);
    $addfriend = $vk->api('friends.add', array('user_id' => $_GET['id']));
    ?>
    <html>
    <head><script type="text/javascript">window.close();</script></head>
    <body></body>
    </html>
<?php 
} catch (VK\VKException $error) {
    echo $error->getMessage();
}