PHP code example of vadimushka / ok-php-sdk

1. Go to this page and download the library: Download vadimushka/ok-php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vadimushka / ok-php-sdk example snippets


$ok = new Client\OkApiClient($application_key, $app_secret_key);

$application_id = 123456789;
$redirect_uri = 'https://example.com/Ok';
$state = 'secret_state_code';
$browser_url = (new Vadimushka\OK\OAuth\OKOAuth)->getAuthorizeUrl(
    response_type: \Vadimushka\OK\OAuth\OkAuthResponseType::CODE,
    application_id: $application_id,
    scope: [
        \Vadimushka\OK\OAuth\OKAuthScope::VALUABLE_ACCESS, 
        \Vadimushka\OK\OAuth\OKAuthScope::LONG_ACCESS_TOKEN
    ],
    redirect_uri: $redirect_uri,
    state: $state,
    layout:  \Vadimushka\OK\OAuth\OKOAuth::W
);

$code = 'CODE';
$application_id = 123456789;
$client_secret = 'client_secret';
$redirect_uri = 'https://example.com/Ok';

$response = (new Vadimushka\OK\OAuth\OKOAuth)->getAccessToken(
    code: $code, 
    application_id: $application_id,
    client_secret: $client_secret,
    redirect_uri: $redirect_uri,
);
$access_token = $response->access_token;

$application_id = 123456789;
$redirect_uri = 'https://example.com/Ok';
$state = 'secret_state_code';
$browser_url = (new Vadimushka\OK\OAuth\OKOAuth)->getAuthorizeUrl(
    response_type: \Vadimushka\OK\OAuth\OkAuthResponseType::TOKEN,
    application_id: $application_id,
    scope: [
        \Vadimushka\OK\OAuth\OKAuthScope::VALUABLE_ACCESS, 
        \Vadimushka\OK\OAuth\OKAuthScope::LONG_ACCESS_TOKEN
    ],
    redirect_uri: $redirect_uri,
    state: $state,
    layout:  \Vadimushka\OK\OAuth\OKOAuth::W
);