Markers API using a Python Script that's run Once per Day

Hello all,

I have a streamer that sets markers and wants me to make clips from their VODs.

I am looking to automate this using ffmpeg and the videos that I download. Ok, cool, so I have all of the ffmpeg stuff scripted out in order to use the timestamp to get the right part of the video and do the trimming for me. Now i want to get the markers programatically. I am looking to run this script maybe once per day, or maybe a couple times in a row every other day.

However, it’s getting the access that I’m confused about. However, the API authentication workflow is confusing to me.

Do I already have the correct permissions?

From what I can tell, since I’m a mod and editor on the streamer’s page, I should have the correct permisssions. From the docs:

Requires a user access token that includes the user:read:broadcast scope.

Reference | Twitch Developers

Authentication

For authentication I got a client ID and secret from Twitch Developers.

I created a brand new app for this and got the client id and secret that I redacted in the code below.

Code

I found the pyTwitchAPI library, and went to use it:

#!/usr/bin/env python3

from twitchAPI.twitch import Twitch
from twitchAPI.oauth import UserAuthenticator
from twitchAPI.types import AuthScope
import pprint
import asyncio

async def main():
    twitch = await Twitch('REDACTED_CLIENT_ID', 'REDACTED_CLIENT_SECRET')

    target_scope = [AuthScope.BITS_READ]
    auth = UserAuthenticator(twitch, target_scope, force_verify=False)
    # this will open your default browser and prompt you with the twitch verification website
    token, refresh_token = await auth.authenticate()
    # add User authentication
    await twitch.set_user_authentication(token, target_scope, refresh_token)

    stream_markers = twitch.get_stream_markers(user_id='', video_id='REDACTED_VIDEO_ID')

    pprint.pprint(await anext(stream_markers))

asyncio.run(main())

But it’s giving me the following error:

twitchAPI.types.MissingScopeException: Require user auth scope USER_READ_BROADCAST

This looks like a permission issue to me, but I can’t figure out why. Any thoughts?

It looks like you’re requesting the bits:read scope, not the user:read:broadcast scope. Additionally you’d have to check with the documentation of the library you’re using, but for Get Stream Markers the params user_id and video_id are mutually exclusive so you should not be trying to send both (even if one is an empty string), so make sure you’re library is appropriately only using the video_id.

That’s what I get for copy-pasting code snippets at 1am :person_facepalming:

That, of course, is correct. Thanks for the second pair of eyes.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.