PHP code example of chatwork / oauth2-chatwork

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

    

chatwork / oauth2-chatwork example snippets


$provider = new ChatWorkProvider(
    getenv('OAUTH2_CLIENT_ID'),
    getenv('OAUTH2_CLIENT_SECRET'),
    getenv('OAUTH2_REDIRECT_URI')
);

$url = $provider->getAuthorizationUrl([
    'scope' => ['users.all:read', 'rooms.all:read_write']
]);

$accessToken = $provider->getAccessToken((string) new AuthorizationCode(), [
    'code' => $code
]);

if ($accessToken->hasExpired()) {
    $refreshedAccessToken = $provider->getAccessToken((string) new RefreshToken(), [
        'refresh_token' => $accessToken->getRefreshToken()
    ]);
}

$resource_owner = $provider->getResourceOwner($accessToken);