Seong Lee
Seong Lee

Reputation: 10520

Retrieving data from Pocket API (oAuth)

I need to retrieve my saved reading list from my Pocket account and it seems that I need to acquire access token through their oAuth to make a request.

I've got consumer key for the access token and as per Pocket API documentation, the request will resemble something like this.

POST /v3/oauth/request HTTP/1.1
Host: getpocket.com
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Accept: application/x-www-form-urlencoded

consumer_key=1234-abcd1234abcd1234abcd1234&
redirect_uri=pocketapp1234:authorizationFinished

My question is... isn't oAuth for 3rd party apps to enable authentication via Google, Facebook account? I don't see how this idea is relevant for my website that will only require access to my own data from Pocket to share on my site.

I understand I will need to authenticate somehow so I can access my data but is oAuth the process I will need to go through to get what I need?

Upvotes: 1

Views: 2004

Answers (2)

Leander
Leander

Reputation: 423

For anyone reading this in 2021 or later, wanting to make a simple script to add articles to their pocket, I came up with this:

1: get your consumer key, via pocket's site.

2: get you access token, using this tool it's very simple. If you want to make an app or something that'll work without it, I guess the above (old) answer might work, didn't test it.

3: Use the following code to add an article:

var request = require('request');

request.post({
        url: 'https://getpocket.com/v3/add',
        form: {
            url: 'https://articleToAdd.com',
            consumer_key: '123456-12abcd1234a1ab12a12abc12',
            access_token: '12345a1a-1ab1-1a12-12a1-1a1234'
        }
    },
    function(err, httpResponse, body) { console.log(httpResponse.body) }
)

Hope it helps someone that is looking to do the same. Retrieving/modifying articles is similar, look here for the specifics.

Upvotes: 1

simo
simo

Reputation: 15478

It seems that they support only 3 legged OAuth flow. You can use Grant in your NodeJS app, or just get access token from here.

Grant

  • save the following example to a file
  • set your key here: key:'...'
  • install the needed dependencies
  • run the file with node.js
  • navigate to http://localhost:3000/connect/getpocket
  • follow the instructions on screen

At the end you'll see your access_token.

var express = require('express')
  , session = require('express-session')

var options = {
  server: {protocol:'http', host:'localhost:3000'},
  getpocket: {key:'...', callback:'/getpocket_callback'}
}

var Grant = require('grant-express')
  , grant = new Grant(options)

var app = express()
app.use(session({secret:'very secret'}))
app.use(grant)

app.get('/getpocket_callback', function (req, res) {
  console.log(req.query)
  res.end(JSON.stringify(req.query, null, 2))
})

app.listen(3000, function () {
  console.log('Express server listening on port ' + 3000)
})

}

Purest

Then you can use Purest to make requests to the Pocket's REST API.

var getpocket = new Purest({provider: 'getpocket'})
getpocket.query()
  .post('get')
  .auth('[API_KEY]', '[ACCESS_TOKEN]')
  .request(function (err, res, body) {
    // body is the parsed JSON response
  })

Upvotes: 3

Related Questions