Last active
March 13, 2020 20:27
-
-
Save mikofski/4249412 to your computer and use it in GitHub Desktop.
use Requests with OAuth 1.0 and Netflix REST API 1.5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"key": "<your-netflix-key>", | |
"secret": "<your-netflix-secret>" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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