I wrote a simple python client for anyone who'd like to see how to get it all to work I'm sure its not the most efficient way to access the API, and there is almost no error checking, but its a start. Download here: http://www.dinkumator.com/netflix.py
Don't expect me to support this, again this is just an "working" example
Thanks for putting that together, although I did notice something that needs a bit of clarification.
The rate limits are: Each developer gets 5000 calls per day for general use not associated with a specific user. Each active user gets 5000 API calls per day allocated to them per application. To be clear, these are allocated per user and are not pooled.
So, basically, you get 5K per day requests for things from the catalog, and you also get 5K per day per user for user related actions (e.g. add/remove things from the queue). In fact, you really DON'T want to pass along the oAuth Token (the user credentials) when doing a catalog lookup. We do add things like eTags to help reduce the number of calls you need to make and help with caching data on your server.
Sorry for any confusion. Yes, Adam is adding this to the FAQ so it's clearer.
One other note: you <may> want to call the catalog with the OAuth access token if you're making a ton of catalog calls and would like to leverage the per user limit of the user of your app.
OK, just to double-check this, Michael says that what I did is best if you dont want to use up the consumer-5000 call limit (which will probably be easy to do when testing...). Thanks for checking JR, glad to know at least someone else has looked through the code.
I just fixed the POST request call, now theres a function to add to a users queue. with this, it should be pretty clear how to perform most queries in the API now.
I noticed that this didn't work quite right for the newer versions of python (for those of us on, say, macs, where 2.4 isn't standard). I've created a newer version, you're welcome to retrieve it from http://www.synedra.org/netflix.py
If there is any interest, I can create an installable module for this. I didn't know how many people were using the current version and didn't want to spend too much time if it's not needed. I'll do some support if there are feature requests or bug fixes needed.
I've made some changes to the app to make it easier for a user to see how various things work.
You can give it a -v to get more verbose output (it will print out the URLs it's using for requests)
You can give it a -a to use the user authentication (without this, it only needs your consumer key/secret, so this allows you to play without it before doing the user key/secret dance)
-q still adds the disc to the queue, assuming the user is authenticated (otherwise it complains and exits)
Not sure if anyone's following along, but I do like making libraries to access REST resources, so I've started putting together an object-oriented python module based around the resources available from the API.
It currently has pretty basic methods for catalog, user, and disc. I'll be updating it as I have time.
Please do. It's fully functional in its current state, if minimally so :-)
It's got some example code and working tests in there so people have examples of how to use the module - and I've organized the objects structure so that the resources requiring user authentication are methods of the User object. Hopefully this will make it easier for people to understand how the various oauth levels work (by example). Seems like this is a big topic of discussion :-)
Not to be too fussy or anything, but could you change my name to "Kirsten"? I know, it's late and all. But still...
Any thoughts on when that hack day might be? The irony of all this is that I started out planning to make a cool cover-flow-ish movie browser, but I got sidetracked by the python thing.
About the hack day? Well, we're going to skip the Open Hack Day in favor of something cooler. (And considering that I was REALLY pulling for the Open Hack Day and think what we're going to be doing is, indeed, much cooler, hopefully will help.)
When we get all the details worked out, we'll let you know.
The pyflix code is pretty much done (well, to version 0.1, anyhow). It needs some documentation love, but the example.py code gives a pretty comprehensive overview of the options available, until I get to documenting all the functions.
Here's the basic description:
Python module for accessing Netflix APIs
This module is set up to access the REST resources from the netflix APIs as objects. There are currently Catalog, User, Disc and Queue objects (as well as a Client object to handle the connections). You can search for titles or people, and there are methods to retrieve authentication tokens. The user object can be used to retrieve metadata about the user as well as look at their rental queue. There are functions for viewing the queues, and adding, deleting, and moving things around. User authentication is only used for user protected resources.
Once you have an API Key, you can insert the key and secret into the example.py file and work with it right away. The example.py code is smart enough to only try to access protected resources if requested via the command line flag -a. That file is fairly well commented to help folks figure out what's possible.
In order to access any of the user-protected resources, follow the instructions in the README to generate consumer request and access tokens for your use in example.py or test.py. In the real world you'll want to be generating those consumer tokens for the specific user using your own code, but it's very helpful to see what you can do at the different levels of access.
There is a test.py file which works with py.test, but you will need to insert the appropriate key/secrets in this as well to make it work for you.
http://code.google.com/p/pyflix/
Folks are welcome to ping me for help/fixes/requests. I think I'll take a break on this for a bit and make a java client :-)
If I run it with just the API_KEY, API_SECRET, APP_NAME and CALLBACK, like so:
kirsten-jones-computer:pyflix kirsten$ python example.py -a
Authorize user access here: https://api-user.netflix.com/oauth/login?application_name=Movie%20browser&oauth_consumer_key=nbf4kr594esg4af25qexwtnu&oauth_token=eqtd656j6r36c6rh38qg548d&oauth_callback=http%3A%2F%2Fwww.synedra.org
and then put this key / secret in EXAMPLE_USER.request:
'key': '<something here>',
'secret': '<something else here>'
and run again.
**************
Then I go to the URL and click "Yes", and insert the "key" and "secret" into example.py under "request".
And then you have to run it again to get an access token:
kirsten-jones-computer:pyflix kirsten$ python bare.py -a
now put this key / secret in EXAMPLE_USER.access so you don't have to re-authorize again:
'key': '<long string>',
'secret': '<short string>'
Then you can put that key/secret under 'access'. Note that the request key/secret are *different* than the access key/secret, and you need *both* in order to be able to do things as a user.
Blech, sent too early. The summary is, if I do 'example.py -a' and follow the instructions until it starts working, it works for me. You need to do it twice to get the user key/secret stuff you need.
Just a note to everyone that I've branched Kirsten's excellent work on the netflix wrapper on github and started adding some properties to the various classes as well as adding a Person class.
I plan to keep development active, so more is on the way.
there are some examples of how my additions work in the readme here:
http://github.com/chrisdrackett/pyflix/blob/ad5f36eb3714217b49ad6275dd7fca9f25f167b9/README.markdown
Its still a work in progress, feel free to fork my work, or send me any comments or suggestions!
Hi kirsten,
I am using pyflix and each time I execute python example.py I run into a ValueError as follows:
.....
Rory Cochrane
The Cocoanuts
*** Now we'll go ahead and try to retrieve a single movie via ID string ***
Checking for http://api.netflix.com/catalog/titles/movies/60002013
Traceback (most recent call last):
File "example.py", line 228, in <module>
movie = getTitleFromID(netflixClient,'http://api.netflix.com/catalog/titles/movies/60002013')
File "example.py", line 77, in getTitleFromID
movie = netflix.catalog.getTitle(arg)
File "/home/mpant/netflix/pyflix-read-only/Netflix.py", line 233, in getTitle
info = simplejson.loads( self.client._getResource( requestUrl ))
File "/usr/lib/python2.5/site-packages/django/utils/simplejson/__init__.py", line 313, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.5/site-packages/django/utils/simplejson/decoder.py", line 321, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.5/site-packages/django/utils/simplejson/decoder.py", line 340, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
When I use python example.py -a I get a Keyerror as follows:
Traceback (most recent call last):
File "example.py", line 215, in <module>
user = getAuth(netflixClient,verbose)
File "example.py", line 36, in getAuth
(tok, url) = netflix.user.getRequestToken()
File "build/bdist.linux-x86_64/egg/Netflix.py", line 53, in getRequestToken
File "build/bdist.linux-x86_64/egg/oauth/oauth.py", line 142, in from_string
Any help in fixing these is appreciated.
Thanks
Meenal
I just checked out the code again and ran through the process of getting and using a user token. I'm able to run example.py with and without -a, and am not seeing the errors you report above. If you give me your API key I can try building a user token with that and see if I get any different results.
You can also run the command with "-v" to see more input/output information.
Is there a way given just an id (say 70019981 for Lost Season 1) to get the title info - certain ids need different id urls (one for movies and one for series)?
Sorry that isn't' as easy as it might be. Another approach is to use the web site URL in the title details as a linking key with the same in the RSS feeds.
I wrote a simple python client for anyone who'd like to see how to get it all to work I'm sure its not the most efficient way to access the API, and there is almost no error checking, but its a start. Download here: http://www.dinkumator.com/netflix.py
Don't expect me to support this, again this is just an "working" example
Tags
JR Conlin – 1 year ago
Thanks for putting that together, although I did notice something that needs a bit of clarification.
The rate limits are: Each developer gets 5000 calls per day for general use not associated with a specific user. Each active user gets 5000 API calls per day allocated to them per application. To be clear, these are allocated per user and are not pooled.
So, basically, you get 5K per day requests for things from the catalog, and you also get 5K per day per user for user related actions (e.g. add/remove things from the queue). In fact, you really DON'T want to pass along the oAuth Token (the user credentials) when doing a catalog lookup. We do add things like eTags to help reduce the number of calls you need to make and help with caching data on your server.
Sorry for any confusion. Yes, Adam is adding this to the FAQ so it's clearer.
Michael Hart – 1 year ago
One other note: you <may> want to call the catalog with the OAuth access token if you're making a ton of catalog calls and would like to leverage the per user limit of the user of your app.
JR Conlin – 1 year ago
Michael would know better than I would regarding rate limits.
Jeremy – 1 year ago
OK, just to double-check this, Michael says that what I did is best if you dont want to use up the consumer-5000 call limit (which will probably be easy to do when testing...). Thanks for checking JR, glad to know at least someone else has looked through the code.
I just fixed the POST request call, now theres a function to add to a users queue. with this, it should be pretty clear how to perform most queries in the API now.
Kirsten Jones – 9 months ago
I noticed that this didn't work quite right for the newer versions of python (for those of us on, say, macs, where 2.4 isn't standard). I've created a newer version, you're welcome to retrieve it from http://www.synedra.org/netflix.py
If there is any interest, I can create an installable module for this. I didn't know how many people were using the current version and didn't want to spend too much time if it's not needed. I'll do some support if there are feature requests or bug fixes needed.
Kirsten Jones – 9 months ago
I've made some changes to the app to make it easier for a user to see how various things work.
You can give it a -v to get more verbose output (it will print out the URLs it's using for requests)
You can give it a -a to use the user authentication (without this, it only needs your consumer key/secret, so this allows you to play without it before doing the user key/secret dance)
-q still adds the disc to the queue, assuming the user is authenticated (otherwise it complains and exits)
Kirsten Jones – 9 months ago
Not sure if anyone's following along, but I do like making libraries to access REST resources, so I've started putting together an object-oriented python module based around the resources available from the API.
It currently has pretty basic methods for catalog, user, and disc. I'll be updating it as I have time.
http://code.google.com/p/pyflix/
JR Conlin – 9 months ago
Cool! Thanks!
Mind if I add it to the Resources page?
Kirsten Jones – 9 months ago
Please do. It's fully functional in its current state, if minimally so :-)
It's got some example code and working tests in there so people have examples of how to use the module - and I've organized the objects structure so that the resources requiring user authentication are methods of the User object. Hopefully this will make it easier for people to understand how the various oauth levels work (by example). Seems like this is a big topic of discussion :-)
JR Conlin – 9 months ago
Heh, you should see what it's like on the OAuth discussion groups. Very cool.
Kirsten Jones – 9 months ago
Not to be too fussy or anything, but could you change my name to "Kirsten"? I know, it's late and all. But still...
Any thoughts on when that hack day might be? The irony of all this is that I started out planning to make a cool cover-flow-ish movie browser, but I got sidetracked by the python thing.
JR Conlin – 9 months ago
Fixed. Caught me in the middle of the update.
About the hack day? Well, we're going to skip the Open Hack Day in favor of something cooler. (And considering that I was REALLY pulling for the Open Hack Day and think what we're going to be doing is, indeed, much cooler, hopefully will help.)
When we get all the details worked out, we'll let you know.
Kirsten Jones – 9 months ago
The pyflix code is pretty much done (well, to version 0.1, anyhow). It needs some documentation love, but the example.py code gives a pretty comprehensive overview of the options available, until I get to documenting all the functions.
Here's the basic description:
Python module for accessing Netflix APIs
This module is set up to access the REST resources from the netflix APIs as objects. There are currently Catalog, User, Disc and Queue objects (as well as a Client object to handle the connections). You can search for titles or people, and there are methods to retrieve authentication tokens. The user object can be used to retrieve metadata about the user as well as look at their rental queue. There are functions for viewing the queues, and adding, deleting, and moving things around. User authentication is only used for user protected resources.
Once you have an API Key, you can insert the key and secret into the example.py file and work with it right away. The example.py code is smart enough to only try to access protected resources if requested via the command line flag -a. That file is fairly well commented to help folks figure out what's possible.
In order to access any of the user-protected resources, follow the instructions in the README to generate consumer request and access tokens for your use in example.py or test.py. In the real world you'll want to be generating those consumer tokens for the specific user using your own code, but it's very helpful to see what you can do at the different levels of access.
There is a test.py file which works with py.test, but you will need to insert the appropriate key/secrets in this as well to make it work for you.
http://code.google.com/p/pyflix/
Folks are welcome to ping me for help/fixes/requests. I think I'll take a break on this for a bit and make a java client :-)
Chris Drackett – 7 months ago
I'm trying to run the example code and I keep getting the following error after entering the EXAMPLE_USER.request key and secret:
Expired or invalid request token
my app also does not appear on http://www.netflix.com/ThirdPartyAccess even though from a users point of view the link seems to have taken place...
Kirsten Jones – 7 months ago
If I run it with just the API_KEY, API_SECRET, APP_NAME and CALLBACK, like so:
kirsten-jones-computer:pyflix kirsten$ python example.py -a
Authorize user access here: https://api-user.netflix.com/oauth/login?application_name=Movie%20browser&oauth_consumer_key=nbf4kr594esg4af25qexwtnu&oauth_token=eqtd656j6r36c6rh38qg548d&oauth_callback=http%3A%2F%2Fwww.synedra.org
and then put this key / secret in EXAMPLE_USER.request:
'key': '<something here>',
'secret': '<something else here>'
and run again.
**************
Then I go to the URL and click "Yes", and insert the "key" and "secret" into example.py under "request".
And then you have to run it again to get an access token:
kirsten-jones-computer:pyflix kirsten$ python bare.py -a
now put this key / secret in EXAMPLE_USER.access so you don't have to re-authorize again:
'key': '<long string>',
'secret': '<short string>'
Then you can put that key/secret under 'access'. Note that the request key/secret are *different* than the access key/secret, and you need *both* in order to be able to do things as a user.
After that if I run 'example.py -a'
Kirsten Jones – 7 months ago
Blech, sent too early. The summary is, if I do 'example.py -a' and follow the instructions until it starts working, it works for me. You need to do it twice to get the user key/secret stuff you need.
Chris Drackett – 6 months ago
Just a note to everyone that I've branched Kirsten's excellent work on the netflix wrapper on github and started adding some properties to the various classes as well as adding a Person class.
http://github.com/chrisdrackett/pyflix/tree/master
I plan to keep development active, so more is on the way.
there are some examples of how my additions work in the readme here:
http://github.com/chrisdrackett/pyflix/blob/ad5f36eb3714217b49ad6275dd7fca9f25f167b9/README.markdown
Its still a work in progress, feel free to fork my work, or send me any comments or suggestions!
JR Conlin – 6 months ago
Awesome! Thanks!
Meenal – 1 month ago
Hi kirsten,
I am using pyflix and each time I execute python example.py I run into a ValueError as follows:
.....
Rory Cochrane
The Cocoanuts
*** Now we'll go ahead and try to retrieve a single movie via ID string ***
Checking for http://api.netflix.com/catalog/titles/movies/60002013
Traceback (most recent call last):
File "example.py", line 228, in <module>
movie = getTitleFromID(netflixClient,'http://api.netflix.com/catalog/titles/movies/60002013')
File "example.py", line 77, in getTitleFromID
movie = netflix.catalog.getTitle(arg)
File "/home/mpant/netflix/pyflix-read-only/Netflix.py", line 233, in getTitle
info = simplejson.loads( self.client._getResource( requestUrl ))
File "/usr/lib/python2.5/site-packages/django/utils/simplejson/__init__.py", line 313, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.5/site-packages/django/utils/simplejson/decoder.py", line 321, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.5/site-packages/django/utils/simplejson/decoder.py", line 340, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
When I use python example.py -a I get a Keyerror as follows:
Traceback (most recent call last):
File "example.py", line 215, in <module>
user = getAuth(netflixClient,verbose)
File "example.py", line 36, in getAuth
(tok, url) = netflix.user.getRequestToken()
File "build/bdist.linux-x86_64/egg/Netflix.py", line 53, in getRequestToken
File "build/bdist.linux-x86_64/egg/oauth/oauth.py", line 142, in from_string
Any help in fixing these is appreciated.
Thanks
Meenal
Kirsten Jones – 1 month ago
Hi Meenal,
I just checked out the code again and ran through the process of getting and using a user token. I'm able to run example.py with and without -a, and am not seeing the errors you report above. If you give me your API key I can try building a user token with that and see if I get any different results.
You can also run the command with "-v" to see more input/output information.
Thanks,
Kirsten
Meenal – 1 month ago
Thanks for the prompt reply Kirsten. I rechecked my settings in example.py and tried again. I see the same error. Can I email you my API key ?
Meenal
Doron – 2 weeks ago
Using http://code.google.com/p/pyflix/ -
Is there a way given just an id (say 70019981 for Lost Season 1) to get the title info - certain ids need different id urls (one for movies and one for series)?
Michael Hart – 2 weeks ago
In the API, the URL <is> the ID.
Doron – 2 weeks ago
I actually only have the numeric part of the url - I am parsing the Netflix RSS feeds (new releases) for my app and trying to get the data via the API
Michael Hart – 1 week ago
Sorry that isn't' as easy as it might be. Another approach is to use the web site URL in the title details as a linking key with the same in the RSS feeds.