How to use add_url API

  • Question
  • Updated 3 years ago
I've started playing with the API using Python Requests but cannot figure out how to use /reader/add_url properly. Why does the following code get a 403 response for add_url?
import requests


login = requests.post('http://www.newsblur.com/api/login', {'username': 'exampleuser', 'password': 'passw0rd'})
print '/api/login', login

addurl = requests.post('http://www.newsblur.com/reader/add_url', {'url' : 'http://blog.newsblur.com'})
print '/reader/add_url', addurl

logout = requests.post('http://www.newsblur.com/api/logout')
Photo of Ali Gündüz

Ali Gündüz

  • 12 Posts
  • 0 Reply Likes

Posted 3 years ago

  • 1
Photo of Samuel Clay

Samuel Clay, Official Rep

  • 5250 Posts
  • 1171 Reply Likes
There are two ways to do this. First is the easy way: use the NewsBlur Python API: http://github.com/samuelclay/NewsBlur.... It uses urllib2, but the important part is the cookieJar it uses.

When you make that login call, you are given a cookie back, called "newsblur_sessionid". You want to hold on to that cookie for subsequent calls. Requests allows you to do this quite easily. It's called sessions and it bakes in this cookie passing: http://docs.python-requests.org/en/la...

If you roll your own ad hoc API, just use requests.session() and you'll be golden. And let me know what you're building. I'd love to help out if I can.
Photo of Ali Gündüz

Ali Gündüz

  • 12 Posts
  • 0 Reply Likes
Hi Sam

To be honest, I was just playing with Python and Requests, and happened to remember that Newsblur has a Python API.

I may actually write an Ubuntu app though. I'll let you know when I have something to test.