Skip to content

Instantly share code, notes, and snippets.

@mikofski
Last active March 13, 2020 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikofski/4249412 to your computer and use it in GitHub Desktop.
Save mikofski/4249412 to your computer and use it in GitHub Desktop.
use Requests with OAuth 1.0 and Netflix REST API 1.5
{
"key": "<your-netflix-key>",
"secret": "<your-netflix-secret>"
}
import requests
from requests_oauthlib import OAuth1
import json
URL = u'http://api-public.netflix.com/catalog/titles'
class Netflix(object):
def __init__(self, keyfile='keyfile.json'):
with open(keyfile,'r') as kf:
keys = json.load(kf)
self.key = unicode(keys.get('key'))
self.secret = unicode(keys.get('secret'))
self.headeroauth = self.oauth_header()
def oauth_header(self):
return OAuth1(self.key, self.secret, signature_type = u'auth_header')
def search(self, term, max_results=25, start_index=0):
params = {'max_results': unicode(max_results), 'output': u'json',
'start_index': unicode(start_index), 'term': unicode(term)}
return requests.get(URL, params=params, auth=self.headeroauth)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment