/** * Initializes VK API * * @package Easy Digital Downloads - Social Login * @since 1.3.0 */ public function edd_slg_initialize_vk() { //vk.com authentcation code if (isset($_REQUEST['state']) && !empty($_REQUEST['state']) && $_REQUEST['state'] == $_SESSION['vkPhpSdkstate'] && isset($_GET['eddslg']) && $_GET['eddslg'] == 'vk') { // //load vk class $vk = $this->edd_slg_load_vk(); //check vk class is loaded or not if (!$vk) { return false; } // Authentication URL $vk_auth_url = $this->vk->_accessTokenUrl . '?client_id=' . $this->vk->_clientId . '&client_secret=' . $this->vk->_clientSecret . '&code=' . $_REQUEST['code'] . '&redirect_uri=' . $this->vk->_redirectUri; $auth_json = $this->edd_slg_get_data_from_url($vk_auth_url); //json_decode( $this->vk->_authJson ); $auth_json = $this->vk->object_to_array($auth_json); if (!empty($auth_json) && !empty($auth_json['access_token'])) { $vkPhpSdk = new VkPhpSdk(); $vkPhpSdk->setAccessToken($auth_json['access_token']); $vkPhpSdk->setUserId($auth_json['user_id']); // API call - get profile $user_profile_data = $vkPhpSdk->api('getProfiles', array('uids' => $vkPhpSdk->getUserId(), 'fields' => 'uid, first_name, last_name, nickname, screen_name, photo_big, email')); $user_profile_data = isset($user_profile_data['response'][0]) ? $user_profile_data['response'][0] : array(); $user_data_session = EDD()->session->get('edd_slg_vk_user_cache'); //Add email field to array if found email address field if (isset($user_data_session['email']) && !empty($user_data_session['email'])) { $user_profile_data['email'] = $auth_json['email']; } $auth_json = array_merge($auth_json, $user_profile_data); //$_SESSION['edd_slg_vk_user_cache'] = $auth_json; EDD()->session->set('edd_slg_vk_user_cache', $auth_json); } } }
<?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'; }
/** * @expectedException VkApiException */ public function testApiWithWrongVkResponse() { $this->transientVkPhpSdkWithWrongVkResponse->api('getProfiles', array('uids' => $this->transientVkPhpSdkWithWrongVkResponse->getUserId())); }
<?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'VkPhpSdk.php'; require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'Oauth2Proxy.php'; // Init OAuth 2.0 proxy $oauth2Proxy = new Oauth2Proxy('5160460', 'nb1sdtbD2Px3IFHBn0XI', 'https://oauth.vk.com/access_token', 'https://oauth.vk.com/authorize', 'code', 'http://localhost/vas/', 'offline,notify,friends,photos,audio,video,wall,ads'); // 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,photo_id,sex,bdate,city,country,home_town,has_photo')); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru"> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="description" content="" /> <title>Рекламный РАБ...</title> <link rel="stylesheet" type="text/css" media="screen" href="/vas/libs/font-awesome/font-awesome.css" /> <link rel="stylesheet" type="text/css" href="packages/ext-theme-crisp-touch/build/resources/ext-theme-crisp-touch-all.css"> <link rel="stylesheet" type="text/css" href="css/icons.css"> <script type="text/javascript" src="ext-all.js"></script> <script type="text/javascript" src="packages/ext-theme-crisp-touch/build/ext-theme-crisp-touch.js"></script> <script type="text/javascript" src="packages/sencha-charts/build/sencha-charts.js"></script> <style> body, html { height: 100%;