This is a R wrapper for the Pocket API. You
can use pocketapi
to access and modify your own
pockets and to add new links to your Pocket programmatically.
Functions include:
pocket_add()
pocket_get()
pocket_archive()
pocket_delete()
pocket_favorite()
pocket_unfavorite()
pocket_tag()
The package is not yet on CRAN.
This package is currently only available on GitHub. You can install
it using devtools
.
# install devtools package if it's not already
install.packages("devtools")
# install package from GitHub
::install_github("correlaid/pocketapi")
devtools
# load package
library(pocketapi)
You need to create a Pocket application in the Pocket
developer portal to access your Pocket data. Don’t worry: this app will
only be visible to you and only serves the purpose of acquiring the
credentials for pocketapi
.
pocketapi
functions:pocketapi function |
what it does | needed permission |
---|---|---|
pocket_get |
get data frame of all your pockets | Retrieve |
all other pocket_* functions |
add new Pocket entries | Modify |
pocketapi
uses the OAuth2 flow provided by the Pocket
Authentication API to get an access token for your App. Because
Pocket does not closely follow the OAuth standard, we could not provide
as smooth an experience as other packages do (e.g. googlesheets4).
Instead, the user has to do the following once to
obtain an access token:
request_token <- get_request_token(consumer_key)
create_authorize_url
in your browser:create_authorize_url(request_token)
:warning: This step is critical: Even if you have authorized your app before and you want to get a new access token, you need to do the authorization in your browser again. Otherwise, the request token will not be authorized to generate an access token!
<- get_access_token(consumer_key, request_token) access_token
You can now already use the package by specifying the consumer key and access token manually as arguments to each function call:
pocketapi::pocket_get(consumer_key = consumer_key, access_token = access_token)
To make it easier to work with the package, you should set them as environment variables.
Important: Never make your consumer_key
and access_token
publicly available - anyone will be able
to access your Pockets!
It is common practice to set API keys in your R environment file so that every time you start R the key is loaded.
All pocketapi
functions access your
consumer_key
and access_token
automatically by
executing Sys.getenv("POCKET_CONSUMER_KEY")
respectively
Sys.getenv("POCKET_ACCESS_TOKEN")
. Alternatively, you can
provide an explicit definition of your consumer_key
and
access_token
with each function call.
In order to add your key to your environment file, you can use the
function edit_r_environ
from the usethis
package:
::edit_r_environ() usethis
This will open your .Renviron
file in the RStudio
editor. Now, you can add the following lines to it:
POCKET_CONSUMER_KEY="yourkeygoeshere"
POCKET_ACCESS_TOKEN="youraccesstokengoeshere"
Save the file and restart R for the changes to take effect.
If your .Renviron
lives at a non-conventional place, you
can also edit it manually using RStudio or your favorite text
editor.
If you don’t want to clutter the .Renviron
file in your
home folder, you can also use a local .Renviron
file in
your project folder and read it in using the readRenviron()
function. In this case, make sure to never share your local
.Renviron
file.
Check out the vignette to see in more detail how to add, get, and modify your Pockets using those functions.
library(pocketapi)
vignette("pocketapi")
This package has some limitations:
modify
action is
not successful, the API will still return “success”. See [issue #26 for a
discussion of weird behaviours of the API.Contributions to this package are welcome. Please see
CONTRIBUTING.md
.