PHP code example of asana / asana
1. Go to this page and download the library: Download asana/asana 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/ */
asana / asana example snippets
$client = Asana\Client::accessToken('ASANA_PERSONAL_ACCESS_TOKEN');
$client = Asana\Client::oauth(array(
'client_id' => 'ASANA_CLIENT_ID',
'client_secret' => 'ASANA_CLIENT_SECRET',
'redirect_uri' => 'https://yourapp.com/auth/asana/callback',
));
$url = $client->dispatcher->authorizationUrl();
$state = null;
$url = $client->dispatcher->authorizationUrl($state);
// $state will be a random number
$state = 'foo';
$url = $client->dispatcher->authorizationUrl($state);
// $state will still be foo
if ($_GET['state'] == $state) {
$token = $client->dispatcher->fetchToken($_GET['code']);
// ...
} else {
// error! possible CSRF attack
}
$me = $client->users->getUser("me");
echo "Hello " . $me->name;
$workspaceGid = $me->workspaces[0]->gid;
$project = $client->projects->createProjectForWorkspace($workspaceGid, array('name' => 'new project'));
echo "Created project with gid: " . $project->gid;
// global:
Asana\Client::$DEFAULTS['page_size'] = 1000;
// per-client:
$client->options['page_size'] = 1000;
// per-request:
$client->tasks->getTasks(array('project' => 1234), array('page_size' => 1000));
$workspaces = $client->workspaces->getWorkspaces();
foreach ($workspaces as $workspace) {
var_dump($workspace);
}
$offset = null;
while (true) {
$page = $client->workspaces->getWorkspaces(null, array('offset' => $offset, 'iterator_type' => null, 'page_size' => 2));
var_dump($page);
if (isset($page->next_page)) {
$offset = $page->next_page->offset;
} else {
break;
}
}