1. Go to this page and download the library: Download buzkall/laravel-ticktick 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/ */
use Arzcode\TickTick\Facades\TickTick;
Route::get('/ticktick/auth', function () {
$state = Str::random(40);
session(['ticktick_state' => $state]);
return redirect(TickTick::getAuthorizationUrl(state: $state));
});
Route::get('/ticktick/callback', function (Request $request) {
abort_unless($request->get('state') === session('ticktick_state'), 403);
$tokenData = TickTick::getAccessTokenFromCode($request->get('code'));
// Persist both tokens: the access token expires, the refresh token
// is what lets you get a new one without sending the user through
// the authorization flow again.
session([
'ticktick_access_token' => $tokenData['access_token'],
'ticktick_refresh_token' => $tokenData['refresh_token'] ?? null,
]);
return redirect('/dashboard');
});
use Arzcode\TickTick\Facades\TickTick;
// Set access token (if not already set in config)
TickTick::setAccessToken(session('ticktick_access_token'));
// Get all projects
$projects = TickTick::projects()->all();
// Each project has 'id' and 'name' properties
foreach ($projects as $project) {
echo $project['name'] . ' (ID: ' . $project['id'] . ')';
}
$project = TickTick::projects()->get($projectId);
// This returns complete project data including all tasks
$data = TickTick::projects()->getData($projectId);
$tasks = $data['tasks'];
// Get all tasks for a specific project
$tasks = TickTick::tasks()->all($projectId);
// Get tasks due today (at any time)
$todayTasks = TickTick::tasks()->today($projectId);
// Get tasks due on a specific date
$tasks = TickTick::tasks()->byDueDate($projectId, '2025-01-15');
// TickTick stores due dates in UTC. Pass a timezone to decide which
// calendar day a task belongs to; it defaults to the app timezone.
$tasks = TickTick::tasks()->today($projectId, 'Europe/Madrid');
$tasks = TickTick::tasks()->byDueDate($projectId, '2025-01-15', 'Europe/Madrid');
// Note: TickTick API doesn't support server-side filtering by date.
// These methods fetch all tasks and filter client-side.
use Arzcode\TickTick\TickTick;
class TaskController extends Controller
{
public function __construct(private TickTick $ticktick)
{
}
public function index()
{
$projects = $this->ticktick->projects()->all();
return view('tasks.index', compact('projects'));
}
}
use Arzcode\TickTick\Exceptions\TickTickException;
try {
$projects = TickTick::projects()->all();
} catch (TickTickException $e) {
if ($e->getStatusCode() === 401) {
// The access token expired, refresh it.
}
report($e->getResponseBody());
}