Kuba Kaktus
Kuba Kaktus

Reputation: 11

Getting Oauth2 token from twitch in python

from rauth import OAuth2Service
import json
class ExampleOAuth2Client:
    def __init__(self, client_id, client_secret):
        self.access_token = None

        self.service = OAuth2Service(
            name="secret",
            client_id="secret",
            client_secret="secret",
            access_token_url="https://id.twitch.tv/oauth2/authorize",
            authorize_url="https://id.twitch.tv/oauth2/authorize",
            base_url="https://id.twitch.tv/",
            response_type="token",
            scope="channel%3Amanage%3Apolls+channel%3Aread%3Apolls",
            state="secret"
        )

        self.get_access_token()

    def get_access_token(self):
        data = {'code': 'bar',
                'grant_type': 'client_credentials',
                'redirect_uri': 'http://localhost'}

        session = self.service.get_auth_session(data=data, decoder=json.loads)

        self.access_token = session.access_token

k = ExampleOAuth2Client
print(k.get_access_token())

The code is originally not mine so I don't know exactly how it works. When I run this it says I need to add positional argument 'self'

Upvotes: 0

Views: 545

Answers (1)

justmcoyy
justmcoyy

Reputation: 15

You need to initialize the ExampleOAuth2Client object properly.

Instead of this:

k = ExampleOAuth2Client

It should look something like:

k = ExampleOAuth2Client('your-client-id', 'your-client-secret')

Upvotes: 1

Related Questions