Teekeks / pyTwitchAPI

A Python 3.7 compatible implementation of the Twitch API, EventSub, PubSub and Chat
https://pytwitchapi.dev
MIT License
254 stars 38 forks source link

Is get_channel_followers working on mock-api ? #272

Closed kantandane closed 11 months ago

kantandane commented 11 months ago

Hi there,

I'm playing with the mock server to discover how Twitch API works before making my real app, and the only method that doesn't work for me is the get_channel_followers(). I always get the same exception :

twitchAPI.type.TwitchResourceNotFound: None

Here is my code

CLIENT_ID = <my client id>
CLIENT_SECRET = <my client secret>
BASE_URL = 'http://localhost:8080/mock/'
AUTH_BASE_URL = 'http://localhost:8080/auth/'
USER_ID = <a user_id generated by my mock server>

async def get_followers():
    twitch = await Twitch(CLIENT_ID,
                          CLIENT_SECRET,
                          base_url=BASE_URL,
                          auth_base_url=AUTH_BASE_URL)
    twitch.auto_refresh_auth = False

    auth = UserAuthenticator(twitch,
                             [AuthScope.MODERATOR_READ_FOLLOWERS],
                             auth_base_url=AUTH_BASE_URL)

    token = await auth.mock_authenticate(USER_ID)

    await twitch.set_user_authentication(token, scope=[AuthScope.MODERATOR_READ_FOLLOWERS])

    followers = await twitch.get_channel_followers(broadcaster_id=USER_ID)
    print(followers.to_dict())

Here is the complete traceback i get

Traceback (most recent call last):
  File "/TestTwitch/followers.py", line 61, in <module>
    asyncio.run(get_followers())
  File "/opt/homebrew/Cellar/python@3.11/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/TestTwitch/followers.py", line 36, in get_followers
    followers = await twitch.get_channel_followers(broadcaster_id=USER_ID)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/TestTwitch/venv/lib/python3.11/site-packages/twitchAPI/twitch.py", line 1809, in get_channel_followers
    return await self._build_iter_result('GET', 'channels/followers', param, AuthType.EITHER, [], ChannelFollowersResult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/TestTwitch/venv/lib/python3.11/site-packages/twitchAPI/twitch.py", line 483, in _build_iter_result
    response = await self._api_request(method, session, _url, auth_type, auth_scope, data=body_data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/TestTwitch/venv/lib/python3.11/site-packages/twitchAPI/twitch.py", line 442, in _api_request
    return await self._check_request_return(session, req, method, url, auth_type, required_scope, data, retries)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/TestTwitch/venv/lib/python3.11/site-packages/twitchAPI/twitch.py", line 421, in _check_request_return
    raise TwitchResourceNotFound(msg)
twitchAPI.type.TwitchResourceNotFound: None

So I'm a bit confused, am I doing something wrong ? Because listing subscriptions etc. works as expected (with the right scope of course).

Thank you

chillymosh commented 11 months ago

This is more down to Twitch CLI and it not being updated to have these new endpoints.

You can simply test in production on your own channel though.

kantandane commented 11 months ago

This is more down to Twitch CLI and it not being updated to have these new endpoints.

You can simply test in production on your own channel though.

Indeed, if I request the URL directly without the library, I get a 404 as well... Thank you !