예제 #1
0
파일: index.php 프로젝트: nilay/vkPhpSdk
<?php

require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'VkPhpSdk.php';
require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'Oauth2Proxy.php';
// Init OAuth 2.0 proxy
$oauth2Proxy = new Oauth2Proxy('2623235', 'FtoFreQZeezym3DCviid', 'https://oauth.vk.com/access_token', 'https://oauth.vk.com/authorize', 'code', 'http://localhost/vkPhpSdk/example', 'offline,notify,friends,photos,audio,video,wall');
// Try to authorize client
if ($oauth2Proxy->authorize() === true) {
    // Init vk.com SDK
    $vkPhpSdk = new VkPhpSdk();
    $vkPhpSdk->setAccessToken($oauth2Proxy->getAccessToken());
    $vkPhpSdk->setUserId($oauth2Proxy->getUserId());
    // API call - get profile
    $result = $vkPhpSdk->api('getProfiles', array('uids' => $vkPhpSdk->getUserId(), 'fields' => 'uid, first_name, last_name, nickname, screen_name, photo_big'));
    echo 'My profile: <br />';
    echo '<pre>';
    print_r($result);
    echo '</pre>';
    // API call - wall post
    $result = $vkPhpSdk->api('wall.post', array('owner_id' => $vkPhpSdk->getUserId(), 'message' => 'Wellcome to vkPhpSdk!'));
    echo 'Wall post response: <br />';
    echo '<pre>';
    print_r($result);
    echo '</pre>';
} else {
    echo 'Error occurred';
}
예제 #2
0
    }
    $res->close();
    if (count($result) > 0) {
        if ("" . $result[0]['vkat'] != "") {
            $vkat = $result[0]['vkat'];
            $ok = true;
        } else {
            goto relogon;
        }
    } else {
        goto relogon;
    }
} else {
    relogon:
    // Init OAuth 2.0 proxy
    $oauth2Proxy = new Oauth2Proxy('5302646', 'LUJf4wzPiglsF5uW8xNe', 'https://oauth.vk.com/access_token', 'https://oauth.vk.com/authorize', 'code', 'http://vas.baminote2.local', 'offline,notify,friends,photos,video,wall,ads');
    if ($oauth2Proxy->authorize() === true) {
        $vkat = $oauth2Proxy->getAccessToken();
        $vkid = $oauth2Proxy->getUserId();
        $ok = true;
    } else {
        echo 'Autorization error';
    }
}
// Try to authorize client
if ($ok === true) {
    // Init vk.com SDK
    $vkPhpSdk = new VkPhpSdk();
    $vkPhpSdk->setAccessToken($vkat);
    $vkPhpSdk->setUserId($vkid);
    $_SESSION['VKAT'] = $vkat;
예제 #3
0
 public function testGetUserId()
 {
     $this->assertEquals($this->object->getUserId(), '6492');
 }