PHP code example of kompas / oauth2-client

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

    

kompas / oauth2-client example snippets




// composer autoload
gue\OAuth2\Client\Provider\Kompas(array(
    'clientId'  =>  'XXXXXXXX',
    'clientSecret'  =>  'XXXXXXXX',
    'redirectUri'   =>  ''
));

try {

    // Try to get an access token (using the client credentials grant)
    $t = $provider->getAccessToken('client_credentials');

    try {

        $provider->setFilterBySite('nasional,megapolitan');
        $latest = $provider->getRssLatest($t);
        $response['latestFiltered'] = json_decode($latest, true); // result filtered
        $mostcommented = $provider->getRssMostCommented($t);
        $response['mostCommentedFiltered'] = json_decode($mostcommented, true); // result filtered
        $provider->setFilterBySite(); // reset filtered
        $mostpopular = $provider->getRssMostPopular($t);
        $response['mostPopularNonFiltered'] = json_decode($mostpopular, true); // result not filtered

    } catch (Exception $e) {

        // Failed to get Rss
        $response = array(
            'status' => false,
            'error' => $e->getMessage()
        );
    }

} catch (Exception $e) {

    // Failed to get access token
    $response = array(
        'status' => false,
        'error' => $e->getMessage()
    );
}

header("Content-Type: application/json");
echo json_encode($response);

$all_latest = $provider->getRssLatest(AccessToken);
$provider->setFilterBySite('nasional,megapolitan'); // (,) delimiter
$filter_latest = $provider->getRssLatest(AccessToken);
$provider->setFilterBySite(); // reset filter
$news_latest = $provider->getRssLatest(AccessToken, 'kompascom', 1, 1);