Your code here differs slightly from your Gist code you have
auth = auth.replace('Bearer', 'OAuth')
here but over there you have
auth = auth.replace('Bearer', 'OAuth2')
Prefixing OAuth2 would cause the 401 error your seeing (I assume that just might be an oversight since it’s fixed here).
EDIT: I noticed you are calling /channel but you do not request the channel_read scope in your token which is required for that endpoint.