PHP code example of poster / api

1. Go to this page and download the library: Download poster/api 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/ */

    

poster / api example snippets




use poster\src\PosterApi;

// Setting up account and token for requests 
PosterApi::init([
    'account_name' => 'demo',
    'access_token' => '4164553abf6a031302898da7800b59fb',
]);

// Reading settings
$result = (object)PosterApi::settings()->getAllSettings(); 
var_dump($result);

// Setting up extras for account 
$result = (object)PosterApi::application()->setEntityExtras([
    'entity_type' => 'settings',
    'extras' => [
        'synced' => true
    ]
]);
var_dump($result);




use poster\src\PosterApi;

PosterApi::init([
    'application_id' => 1, // Your application id (client_id) 
    'application_secret' => '1362900b6c441dd0f219bd0974c7e2b8', // secret
    'redirect_uri' => 'http://example.com/poster/auth',
]);

$oAuthUrl = PosterApi::auth()->getOauthUrl();

// Redirect user to this url to start authorization
http_redirect($oAuthUrl);

 

use poster\src\PosterApi;

$result = (object)PosterApi::auth()->getOauthToken($_GET['account'], $_GET['code']);

if (empty($result->access_token)) {
    echo "Poster auth error";
	var_dump($result);
	die;
}

// In case of successful auth, token and account name would be placed into config automatically
$settings = PosterApi::settings()->getAllSettings();
var_dump($settings);