Skip to content

Latest commit

 

History

History
181 lines (149 loc) · 6.69 KB

API.md

File metadata and controls

181 lines (149 loc) · 6.69 KB

API

Authentication

The Pocket Authentication API uses a variant of OAuth 2.0 for authentication. OAuth 2.0 is meant to be straightforward to implement, and also provides increased security for user authentication because 3rd party client apps no longer need to request or store a user's login information to authenticate with Pocket. Check Pocket Authentication API for more details.

####You have to do several steps to authorize in Pocket: #####Step 1. Obtain a Platform Consumer Key #####Step 2. Get a request token

var authentication = new ClientAuthentication(consumerKey);
var requestToken = await authentication.getRequestToken(redirectUrl);

#####Step 3: Get authorization url to redirect user to Pocket to continue authorization You can do it using the request token recieved in step 2

var url = ClientAuthentication.getAuthorizeUrl(requestToken, redirectUrl);
// provide this url to user 

#####Step 4: Receive the callback from Pocket When the user has authorized (or rejected) your application's request token, Pocket will return the user to your application by opening the redirectUrl that you provided in step 2.

#####Step 5: Convert a request token into a Pocket access token When user is authorized in Pocket you can convert the request token to an access token

var userData = await authentication.getAccessToken(requestToken);
var accessToken = userData.accessToken;
var userName = userData.userName;
// use this data to work with Pocket

Pocket Client

Once you got access token you can create Pocket client

var client = new Client(consumerKey, accessToken);

######Here is the list of available methods. All methods are async and return Future:

Method Description
getData({RetrieveOptions options}) get list of pocket items base on retrieve options
addItem(ItemToAdd newItem) add new item
addUrl(String newUrl) add new item based on provided url
modify(List actions) bulk modification of pocket items based on provided list of actions
archive(int itemId, {DateTime time}) move an item to the user's archive
delete(int itemId, {DateTime time}) permanently remove an item from the user's account
favorite(int itemId, {DateTime time}) mark an item as a favorite
unFavorite(int itemId, {DateTime time}) remove an item from the user's favorites
reAdd(int itemId, {DateTime time}) move an item from the user's archive back into their unread list
clearTags(int itemId, {DateTime time}) remove all tags from an item
addTags(int itemId, List tags, {DateTime time}) add one or more tags to an item
removeTags(int itemId, List tags, {DateTime time}) remove one or more tags from an item
replaceTags(int itemId, List tags, {DateTime time}) replace all of the tags for an item with the one or more provided tags
renameTag(int itemId, String oldTag, String newTag, {DateTime time}) rename a tag. This affects all items with this tag

######Here is the list of available actions:

Action
AddAction
ArchiveAction
ReAddAction
FavoriteAction
UnFavoriteAction
DeleteAction
ClearTagsAction
RenameTagAction
AddTagsAction
RemoveTagsAction
ReplaceTagsAction

###Examples

getData({RetrieveOptions options})
var options = new RetrieveOptions()
 ..since = new DateTime(2015, 5, 4)
 ..search = 'Some search query'
 ..domain = 'http://domain.test'
 ..contentType = ContentType.video
 ..detailType = DetailType.complete
 ..isFavorite = true
 ..sortType = SortType.site
 ..state = State.all
 ..tag = 'cats'
 ..count = 100
 ..offset = 10;

var response = await client.getData(options: options);
Map<String, PocketData> items = response.items;
// do whatever you want with pocket items
addItem(ItemToAdd newItem)
var newItem = new ItemToAdd('http://www.funnycatpix.com/')
 ..title = 'FUNNY CAT PICTURES'
 ..tweetId = '123456'
 ..tags = ['cats', 'cool', 'share'];

PocketData data = await client.addItem(newItem);
// do whatever you want with received data
addItem(ItemToAdd newItem)
PocketData data = await client.addUrl(newUrl);
// do whatever you want with received data
modify(List actions)
var actions = [
	new DeleteAction(12340, time: new DateTime.fromMillisecondsSinceEpoch(1430686800000)),
	new ArchiveAction(12341, time: new DateTime.fromMillisecondsSinceEpoch(1430686800001)),
	new FavoriteAction(12342, time: new DateTime.fromMillisecondsSinceEpoch(1430686800002))
];

ActionResults result = await client.modify(actions);
archive(int itemId, {DateTime time})
ActionResults result = await client.archive(12341, time: new DateTime.fromMillisecondsSinceEpoch(1430686800001));
delete(int itemId, {DateTime time})
ActionResults result = await client.delete(12341, time: new DateTime.fromMillisecondsSinceEpoch(1430686800001));
favorite(int itemId, {DateTime time})
ActionResults result = await client.favorite(12341, time: new DateTime.fromMillisecondsSinceEpoch(1430686800001))
unFavorite(int itemId, {DateTime time})
ActionResults result = await client.unFavorite(12341, time: new DateTime.fromMillisecondsSinceEpoch(1430686800001));
reAdd(int itemId, {DateTime time})
ActionResults result = await client.reAdd(12341, time: new DateTime.fromMillisecondsSinceEpoch(1430686800001));
clearTags(int itemId, {DateTime time})
ActionResults result = await client.clearTags(12341, time: new DateTime.fromMillisecondsSinceEpoch(1430686800001));
addTags(int itemId, List tags, {DateTime time})
ActionResults result = await client
	.addTags(12346, ['firstTag', 'secondTag'], time: new DateTime.fromMillisecondsSinceEpoch(1430686800006));
removeTags(int itemId, List tags, {DateTime time})
ActionResults result = await client
	.removeTags(12346, ['firstTag', 'secondTag'], time: new DateTime.fromMillisecondsSinceEpoch(1430686800006));
replaceTags(int itemId, List tags, {DateTime time})
ActionResults result = await client
	.replaceTags(12346, ['firstTag', 'secondTag'], time: new DateTime.fromMillisecondsSinceEpoch(1430686800006));
renameTag(int itemId, String oldTag, String newTag, {DateTime time})
ActionResults result = await client
	.renameTag(12346, 'firstTag', 'secondTag', time: new DateTime.fromMillisecondsSinceEpoch(1430686800006));