PHP code example of imper86 / php-asana-api

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

    

imper86 / php-asana-api example snippets


$credentials = new Credentials(
    'your_client_id',
    'your_client_secret',
    'http://localhost:8000/asana' //redirect_uri
);

$tokenRepository = new FileTokenRepository(__DIR__ . '/asana_tokens');

$client = new Client($credentials, $tokenRepository);

$state = 'your-random-secret-state';
header(sprintf('Location: %s', $client->auth()->authUri($state)));

if ($state === $_GET['state'] ?? null) {
    throw new Exception('CSRF?!');
}

$client->authenticateWithCode($_GET['code']);

$client->getUserGid();

$userGid = 'your-user-gid';
$client = new Client($credentials, $tokenRepository, $userGid);

$client->organizations()->(...)
$client->projects()->(...)
$client->sections()->(...)
$client->tags()->(...)
$client->tasks()->(...)
$client->teams()->(...)
$client->users()->(...)
$client->workspaces()->(...)

$projects = $client->teams()->projects()->list('teamgid');