PHP code example of yireo / producteev-client

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

    

yireo / producteev-client example snippets


// Include all composer packages
ts ID and secret
$client = new \Yireo\ProducteevClient\Client($clientId, $clientSecret);

// Retrieve a current access token from cookie, if there
$client->retrieveAccessTokenFromCookie();

// Set the redirect URL
$redirectUrl = 'http://example.com/';
$client->setRedirectUrl($redirectUrl);

// When authenticating via OAuth2, Producteev will redirect back to us with a "code" set
if (!empty($_REQUEST['code'])) {
    $client->setAuthenticationCode($_REQUEST['code']);
    $client->retrieveAccessTokenToCookie();

    // Redirect to our same page again, removing the "code" part
    header('Location: ' . $redirectUrl);
    exit;
}

// When there is no valid access token, this will initiate OAuth2 authentication including a redirect to the Producteev webpage
if($client->isAccessTokenValid() === false) {
    $client->authenticate();
}

// Example call
echo '<pre>';
print_r($client->getResource('users')->me());
echo '</pre>';

$networks = $client->getResource('networks')->items();

$me = $client->getResource('users')->me();

$exampleUser = $client->getResource('users')->findByEmail('[email protected]');

$defaultProject = $client->getResource('users')->getMyDefaultProject();

$projectData = ['title' => 'Test Project', 'description' => 'Test description'];
$projectId = $client->getResource('projects')->create($projectData);

$taskDeadline = date('c', strtotime('tomorrow'));
$taskSubtasks = [['title' => 'Some subtask', 'status' => 1], ['title' => 'Another subtask', 'status' => 1]];
$taskData = ['title' => 'Test task', 'deadline' => $taskDeadline, 'subtasks' => $taskSubtasks, 'responsibles' => [$exampleUser], 'project' => ['id' => $projectId]];
$taskId = $client->getResource('tasks')->create($taskData);
$client->getResource('tasks')->removeResponsible($taskId, $me);

$projects = $client->getResource('projects')->items();

$projects = $client->getResource('projects')->search('office);