Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

bouiboui/pokket-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pokket-php

Latest Version on Packagist Software License SensioLabsInsight

PHP SDK to access the Pocket API (v3, currently).

Wait, why don't you call it Pocket API PHP SDK or something similar then?

It's actually forbidden because business™.

I'm a big fan of Pocket and I have some ideas I want to try out thanks to its API. The other librairies I found on Github were either too small, too big, or not documented enough for my needs. duellsy/pockpack seems very nicely done, it's a shame I found it too late.

Install

$ composer require bouiboui/pokket-php

Usage

Note: For a complete example: example/index.php

Initialize Pokket with your Consumer key and Redirect URI (classic OAuth)

$pokket = new PokketAPI(
    '1234-abcd1234abcd1234abcd1234', // Consumer key
    'https://yourdomain.tld/' // Redirect uri
);

First we ask the user to login

if (!array_key_exists('pokket.token.request', $_SESSION)) {
    $pokket->requestUserAccess($_SESSION['pokket.token.request'] = $pokket->getRequestToken());
} 

Then we fetch an Access token

if (!array_key_exists('pokket.token.access', $_SESSION)) {
    $_SESSION['pokket.token.access'] = $pokket->getAccessToken($_SESSION['pokket.token.request']);
}
$pokket->setAccessToken($_SESSION['pokket.token.access']);

Now we can get down to business™

// Retrieve user posts
$retrieveQuery = RetrieveQuery::build()
    ->withState(RetrieveQuery::STATE_UNREAD)
    ->withSort(RetrieveQuery::SORT_TITLE)
    ->withDetailType(RetrieveQuery::DETAIL_TYPE_SIMPLE)
    ->withCount(100);

$posts = $pokket->retrieve($retrieveQuery);

// Display results
header('Content-type: application/json;Charset=utf8');
echo json_encode($posts);

The code above returns (minus the pretty format):

{
	"status": 1,
	"complete": 1,
	"list": {
		"2093856": {
			"item_id": "2093856",
			"resolved_id": "2093856",
			"given_url": "http://www.csie.ntu.edu.tw/~cjlin/libsvm/",
			"given_title": "",
			"favorite": "0",
			"status": "0",
			"time_added": "1390842458",
			"time_updated": "1390927561",
			"time_read": "0",
			"time_favorited": "0",
			"sort_id": 74,
			"resolved_title": "LIBSVM -- A Library for Support Vector Machines",
			"resolved_url": "http://www.csie.ntu.edu.tw/~cjlin/libsvm/",
			"excerpt": "LIBSVM -- A Library for Support Vector Machines Chih-Chung Chang and Chih-Jen Lin  Version 3.19 released on October 27, 2014. It conducts some minor fixes.LIBSVM tools provides many extensions of LIBSVM. Please check it if you need some functions not supported in LIBSVM.",
			"is_article": "0",
			"is_index": "1",
			"has_video": "0",
			"has_image": "1",
			"word_count": "961"
		},
		" ... and 99 more elements ... "
	},
	"error": null,
	"search_meta": {
		"search_type": "normal"
	},
	"since": 1460836019
}

Credits

License

Unlicense. Public domain, basically. Please treat it kindly. See License File for more information.

This project uses the following open source projects