twitch-observer icon indicating copy to clipboard operation
twitch-observer copied to clipboard

Question - Auth token

Open Firerazer opened this issue 4 years ago • 12 comments

Good morning/afternoon/evening, where ever you are located around the world.

We are trying to put in place your bots, and we are confused, to say the least. After several hours, we are not able to link the OAuth token you require to run your bot and the way twitch is providing the token. Do you have insights about this?

Best regards

Firerazer avatar Jun 20 '20 19:06 Firerazer

Hello again @Firerazer!

We are currently not aware of any problems with the bot authentication.

You need to perform the following steps:

  • Obtain your personal OAuth token at e.g. Twitch Chat OAuth Password Generator
  • Initialize the observer using that OAuth token: observer = Observer('Nick', 'oauth:abcdefghijklmnopqrstuvwxyz0123')
  • Let the observer connect to Twitch using observer.start()

Maybe you can provide additional information to your problem?

  • What is the error message you are receiving from the bot?
  • How is the structure of your OAuth token looking like? Is it the same?
  • Are you aware of any OAuth changes on Twitch side?
  • Is your OAuth token up-to-date?

Thanks!

PythooonUser avatar Jun 22 '20 09:06 PythooonUser

Additional information can also be found on our wiki.

PythooonUser avatar Jun 22 '20 09:06 PythooonUser

I wait for my programmer return with your instructions. Thanks for the feedback

Firerazer avatar Jun 22 '20 18:06 Firerazer

By the way, you know that I find nowhere in your wiki the link you have provided me?...

Moreover, after providing the oauth token, we were trying to run this: observer = Observer('RedCircuitBot', 'oauth:**********') observer.start() observer.join_channel('Spectre860') observer.send_message('Hello', 'Spectre860') observer.leave_channel('Spectre860') observer.stop()

nothing trigger in the channel, we cannot see the bot logging in the chat server side, no error appearing

Firerazer avatar Jun 22 '20 18:06 Firerazer

OAuth token was 25minutes old at the test time. Obtained from your provided website, with the bot account connected and accepting the connection. Structure of the oauth code is mixing letters and numbers From twitch side, the developer code is not mentioning your link, but more a complete request on twitch side: https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/

Firerazer avatar Jun 22 '20 20:06 Firerazer

Hey @Firerazer,

thanks for getting back to us.

The link to the Password Generator can be found in our wiki for writing a greeter bot (the link I provided above) or at the official Twitch site within the IRC guide.

I looked into the code sample you posted above and found the solution to your problem.

join_channel takes in the channel name. What you are providing is the display name. Usually the channel name is just the lowercase version of the display name (shown in the URL, e.g. in my case https://www.twitch.tv/pythooonuser). The display name is arbitrary (as far as I know) and can be changed on Twitch side. However, the channel name remains the same.

In my case PythooonUser does not work, however, pythooonuser does work.

Please let me know if that solved your issue!

PythooonUser avatar Jun 23 '20 06:06 PythooonUser

Good evening, Thanks for your help. We were successfully having the bot connecting to 3 different chats at the same time for doing echo messages. The problem is that when executing this, the console is blocked and only way to exit properly is to kill the server and restart it. This tho block us to use this bot in a clean way to handle our commands. We are using Python3 on a Win machine, with a plan to run once working on a linus server.

Firerazer avatar Jun 25 '20 17:06 Firerazer

Hey @Firerazer,

glad to hear you got the bot working now.

I'm not exactly sure what you are referring to with your question "to use the bot in a clean way". Please have a look at our code example for a working bot.

import time
from twitchobserver import Observer

with Observer('TwitchChatBot', 'oauth:abcdefghijklmnopqrstuvwxyz0123') as observer:
    observer.join_channel('channel')

    while True:
        try:
            for event in observer.get_events():
                if event.type == 'TWITCHCHATJOIN' and event.nickname != 'TwitchChatBot':
                    observer.send_message('🍺 Welcome {}!'.format(event.nickname), event.channel)

            time.sleep(1)

        except KeyboardInterrupt:
            observer.leave_channel('channel')
            break

In principle you can let the bot run in a main event loop, that is the while True: part. In this loop you can listen to the KeyboardInterrupt event (which is Ctrl+C), so you can gracefully exit the bot by leaving channels and cleaning-up any relevant things.

If you want to let the bot somehow run in the background then I'm not exactly sure how to do that. I guess there is a python way of running scripts in the background or redirecting the scripts output to dev/null on *unix systems.

PythooonUser avatar Jun 25 '20 18:06 PythooonUser

Ctrl-C doesn't exit gracefully, I normally see a few lines of crashdump and it hangs the command window. I had confirmed the Keyboard Interrupt was Ctrl-C. Ctrl-C with your basic send message example does the same behavior, inserting observer.stop() was the only way I could get it to exit cleanly on it's own. I'm not very familiar with Python so I was doing research and thus didn't get back sooner. I was thinking it was something I was missing.

spectreGIT avatar Jun 25 '20 18:06 spectreGIT

Hey @spectreGIT!

I don't know what you mean with your basic send message example, but I just used the above posted code taken from the wiki and I get no error messages when exiting using Ctrl+C.

There shouldn't be the need to call observer.stop() as that is automatically called when leaving the while loop. That is because we are using the with ... as syntax here.

Sometimes it takes a while for the keyboard interrupt to take effect as observer.stop() waits until every outgoing event is send.

PythooonUser avatar Jun 25 '20 18:06 PythooonUser

Good day! Sorry for the delay, normal work taking priority over this ;) we have managed to find way to make it work as we want it to work. Nevertheless, we don't find 2 stuff:

  • Add a spam protection
  • Allow only mods and higher to use some commands without hardcoding the pseudo. is it somewhere in the code, or have to be done? Thanks,

Firerazer avatar Jul 05 '20 11:07 Firerazer

Hey @Firerazer,

you can have a look at e.g. the userstate event that provides a tag called mod. May that be what you need?

PythooonUser avatar Jul 05 '20 14:07 PythooonUser