Wunderlist PHP API
A PHP wrapper for the Wunderlist API. Feedback or bug reports are appreciated.
Composer package available.
Laravel integration available.
Requirements
- PHP 5.6 or higher
- Guzzle
- Registered Wunderlist App
Get started
To use the Wunderlist API you have to register yourself as a developer at the Wunderlist Developer Platform and create an application. You will receive your clientId
and clientSecret
.
You must provide APP URL
and AUTH CALLBACK URL
.
Installation
I strongly advice using Composer to keep updates as smooth as possible.
$ composer require "wilsonpinto/wunderlist"
Initialize the class
use Wilsonpinto\Wunderlist\Wunderlist;
$wunderlist = new Wunderlist('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', 'YOUR_API_CALLBACK');
$csrfToken = md5(time());
//store the $csrfToken to compare against callback state token
echo "<a href='{$wunderlist->getLoginUrl($csrfToken)}'>Login with Wunderlist</a>";
Authenticate user
$code = $_GET['code']; //grab OAuth callback code
$state = $_GET['state']; //grab OAuth callback state
$csrfToken = $__SESSION['csrfToken']; // grab stored $csrfToken and compare against $state
if ($state == $csrfToken) {
$token = $wunderlist->auth($code);
$wunderlist->refreshAccessToken($token);//store access token
echo 'Your name is: ' . $wunderlist->user()->name;
}else{
echo 'Defending against CSRF Attacks';
}
Get user lists
// set user access token
$wunderlist->refreshAccessToken($token);
// get all user lists
$lists = $wunderlist->lists()->all();
echo '<pre>';
print_r($lists);
echo '<pre>';
All methods return the API data so you can directly access the data.
Exceptions
use Wilsonpinto\Wunderlist\WunderlistException;
try{
$wunderlist->refreshAccessToken($token);
$user = $wunderlist->user();
}
}catch(WunderlistException $e){
echo $e->getMessage();
}
Available methods
Laravel Integration
After updating composer, add new entry to the services array in config/services.php and update your env variables
'wunderlist' => [
'clientId' => env('WUNDERLIST_CLIENT_ID'),
'clientSecret' => env('WUNDERLIST_CLIENT_SECRET'),
'apiCallback' => env('WUNDERLIST_CALLBACK'),
'accessToken' => env('WUNDERLIST_ACCESS_TOKEN', '')
],
//env variables
WUNDERLIST_CLIENT_ID=
WUNDERLIST_CLIENT_SECRET=
WUNDERLIST_CALLBACK=
WUNDERLIST_ACCESS_TOKEN= //optional
Add the ServiceProvider to the providers array in config/app.php
Wilsonpinto\Wunderlist\WunderlistServiceProvider::class
Wunderlist facade
Wunderlist::avatar();
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Security
If you discover any security related issues, please email wilsonpinto360@gmail.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.