api: Add oath token to the request header
This commit is contained in:
parent
1053dfad9a
commit
4de664eadc
3 changed files with 10 additions and 4 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,5 +1,7 @@
|
|||
__pycache__
|
||||
*.swp
|
||||
.token
|
||||
.oath
|
||||
.secret
|
||||
server.conf
|
||||
.*.log
|
||||
|
|
6
main.py
6
main.py
|
@ -5,7 +5,7 @@ import cherrypy
|
|||
from cherrypy.process.plugins import Daemonizer
|
||||
from twitch import TwitchClient
|
||||
|
||||
ver = '1.9-pre'
|
||||
ver = '1.9.0-pre-2'
|
||||
|
||||
|
||||
class FleastServer(object):
|
||||
|
@ -13,6 +13,8 @@ class FleastServer(object):
|
|||
try:
|
||||
with open('.token', 'r') as reader:
|
||||
self.twitch_token = reader.read().strip()
|
||||
with open('.oath', 'r') as reader:
|
||||
self.oath_token = reader.read().strip()
|
||||
with open('./web/fl.html', 'r') as reader:
|
||||
self.index_page = reader.read()
|
||||
with open('./web/fl_template_main.html', 'r') as reader:
|
||||
|
@ -21,7 +23,7 @@ class FleastServer(object):
|
|||
self.templ_stream = reader.read()
|
||||
with open('./web/fl_template_lang.html', 'r') as reader:
|
||||
self.templ_lang = reader.read().splitlines()
|
||||
self.client = TwitchClient(self.twitch_token, freq=1)
|
||||
self.client = TwitchClient(self.twitch_token, self.oath_token, freq=1)
|
||||
except:
|
||||
print("Cannot read token for twitch app or templates, abort.")
|
||||
exit(1)
|
||||
|
|
|
@ -6,13 +6,15 @@ from urllib.parse import quote
|
|||
|
||||
|
||||
class TwitchClient:
|
||||
def __init__(self, token, freq=2):
|
||||
def __init__(self, token, oath, freq=2):
|
||||
self.token = token
|
||||
self.oath = oath
|
||||
self.lock = threading.Lock()
|
||||
|
||||
self.header_v5 = {'Client-ID': self.token,
|
||||
'Authorization': 'Bearer ' + self.oath,
|
||||
'Accept': 'application/vnd.twitchtv.v5+json'}
|
||||
self.header_v6 = {'Client-ID': self.token}
|
||||
self.header_v6 = {'Client-ID': self.token, 'Authorization': 'Bearer '+self.oath}
|
||||
self.urlbase_v5 = 'https://api.twitch.tv/kraken'
|
||||
self.urlbase_v6 = 'https://api.twitch.tv/helix'
|
||||
|
||||
|
|
Loading…
Reference in a new issue