Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when getting followed channels #9

Closed
Kperroch opened this issue Feb 24, 2023 · 23 comments
Closed

Issue when getting followed channels #9

Kperroch opened this issue Feb 24, 2023 · 23 comments

Comments

@Kperroch
Copy link

image

I have those issues when the server launch.
All the parameters seems to be fine as it can find user object.
Any Idea of how to solve ?

@micahmo
Copy link
Owner

micahmo commented Feb 24, 2023

Hey @Kperroch, I just retested and verified that, with a good Client ID and Client Secret, the API still behaves properly.

I see these suggestions from the Twitch API library.

image

Could the problem be number 3? These are often the same, but not always. The actual ID should be in the URL of your page.

EDIT: Actually, this part seems to indicate that the user lookup was successful, but that the user doesn't follow any channels. Is that true?

image

@Kperroch
Copy link
Author

Kperroch commented Feb 24, 2023

Is the issue the account follow more than 10 other channels and as if the Client ID was incorrect the Api couldn't bi able to retrieve the user

EDIT : I think the log display 0 channel because of the issue above where it is saying : "The resource you tried to access was not valid"

@micahmo
Copy link
Owner

micahmo commented Feb 24, 2023

I think the log display 0 channel because of the issue above

Hmm, you may be right. It's hard to tell because every call goes through UseTwitchApi.

I just pushed a new version with a tiny bit of extra logging to see exactly which API call is failing. Can you try it?

@Kperroch
Copy link
Author

Just updated with latest version still the same issue no more logs
image

@micahmo
Copy link
Owner

micahmo commented Feb 24, 2023

Thank you! I do see the thing I added which is the method being invoked. In both cases, it's RetrieveChannels that's failing. But that's not as helpful as I was hoping. I did add a tiny bit more logging and published a new image, if you want to try again, but I'm not sure it'll help.

It's not clear to me what's going on here, as this works for me and others. Is the username that you put in TWITCH_USERNAME the same as the one under which you created the Client Secret and ID?

Any chance you'd want to DM me your username for me to try on my system? If not I totally understand.

Sorry about this!

@Kperroch
Copy link
Author

Just sent you an email

@styler2go
Copy link

Hey there! It seems like I have exactly the same issue.

@styler2go
Copy link

 21:14:42.637 INF >> [UseTwitchApi] Attempting to retrieve new access token using client credentials flow.
 21:14:44.111 INF >> [RetrieveAccessToken] Successfully got new access token and was able to retrieve user { user data here}.
 21:14:44.546 INF >> [RetrieveChannels] Found that user xyz follows 0 channels:
 21:14:44.546 WRN >> [UpdateChannels] Got empty response when querying user follows
 21:14:44.546 ERR >> [TwitchApiManager] Encountered an error invoking method GetUsersFollowsAsync on the Twitch API: TwitchLib.Api.Core.Exceptions.BadResourceException: The resource you tried to access was not valid.
   at TwitchLib.Api.Core.HttpCallHandlers.TwitchHttpClient.HandleWebException(HttpResponseMessage errorResp)
   at TwitchLib.Api.Core.HttpCallHandlers.TwitchHttpClient.GeneralRequest(String url, String method, String payload, ApiVersion api, String clientId, String accessToken)
   at TwitchLib.Api.Core.ApiBase.<>c__DisplayClass16_0`1.<TwitchGetGenericAsync>b__1()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__277_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at TwitchLib.Api.Core.ApiBase.<>c__DisplayClass16_0`1.<<TwitchGetGenericAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at twitch2tuner.TwitchApiManager.UseTwitchApi[T](Func`2 action, String method, Boolean tryRefreshToken) in /src/twitch2tuner/TwitchApiManager.cs:line 46
 21:14:44.737 WRN >> [UpdateChannels] Trying to update channels' statuses, but no channels were found.
 21:14:44.743 INF >> [StartServer] Starting server on http://+:22708
 21:14:44.735 ERR >> [TwitchApiManager] Encountered an error invoking method GetUsersAsync on the Twitch API: TwitchLib.Api.Core.Exceptions.BadRequestException: Your request failed because either:
 1. Your ClientID was invalid/not set.
 2. Your refresh token was invalid.
 3. You requested a username when the server was expecting a user ID.
   at TwitchLib.Api.Core.HttpCallHandlers.TwitchHttpClient.HandleWebException(HttpResponseMessage errorResp)
   at TwitchLib.Api.Core.HttpCallHandlers.TwitchHttpClient.GeneralRequest(String url, String method, String payload, ApiVersion api, String clientId, String accessToken)
   at TwitchLib.Api.Core.ApiBase.<>c__DisplayClass16_0`1.<TwitchGetGenericAsync>b__1()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__277_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at TwitchLib.Api.Core.ApiBase.<>c__DisplayClass16_0`1.<<TwitchGetGenericAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at twitch2tuner.TwitchApiManager.UseTwitchApi[T](Func`2 action, String method, Boolean tryRefreshToken) in /src/twitch2tuner/TwitchApiManager.cs:line 46
 21:14:44.755 INF >> [WebServer] Running HTTPListener: Unosquare HTTP Listener
 21:14:44.757 INF >> [WebServer] Web server prefix 'http://+:22708/' added.
 21:14:44.818 INF >> [WebServer] Started HTTP Listener
 21:14:44.826 INF >> [StartServer] Server is started and ready to receive connections.

@micahmo
Copy link
Owner

micahmo commented Feb 24, 2023

Just sent you an email

@Kperroch Thanks! With your username, I was able to discover a different bug. (When converting Follows to Users, I was hitting a limit of 100 per request).

However your and @styler2go's problem is clearly before that, when first looking up the Follows, which works fine for me.

Would either of you be willing to run direct Twitch API commands? These work on PowerShell for Windows (I can write them for bash if needed).

First, use your Client ID and Client Secret to retrieve an AccessToken.

(iwr -method post "https://id.twitch.tv/oauth2/token?client_id=YOURCLIENTID&client_secret=YOURCLIENTSECRET&grant_type=client_credentials&scope=user:read:subscriptions").Content

You should get a response like this.

{"access_token":"YOURACCESSTOKEN","expires_in":5203151,"scope":["user:read:subscriptions"],"token_type":"bearer"}

Then make a request like this to get your user's ID.

(iwr -method get https://api.twitch.tv/helix/users?login=YOURUSERNAME -header @{"client-id" = "YOURCLIENTID"; "Authorization" = "Bearer YOURACCESSTOKEN" }).Content

Finally, using the id from that output, make a request to get your follows.

(iwr -method get https://api.twitch.tv/helix/users/follows?from_id=YOURID -header @{"client-id" = "YOURCLIENTID"; "Authorization" = "Bearer YOURACCESSTOKEN" }).Content

That would help me understand if this is a problem with Twitch's API or my application. Thanks!

@styler2go
Copy link

Response from this, after a while, is:

Invoke-WebRequest: {"error":"Not Found","status":404,"message":""}

Seems like the API is not working?

@micahmo
Copy link
Owner

micahmo commented Feb 24, 2023

Response from this

Which command was that the response to? The first one?

@styler2go
Copy link

styler2go commented Feb 24, 2023

Oh sorry it's the last one. Every other request ran through quickly and successfully

@Kperroch
Copy link
Author

@micahmo Did you make a change regarding the issue of the limit of 100 ? :)

@micahmo
Copy link
Owner

micahmo commented Feb 24, 2023

Oh sorry it's the last one. Every other request ran through quickly and successfully

@styler2go Wow, very interesting! Seems like it's related to the Twitch API and/or the application you created in their dev console. But there aren't really a lot of options. Maybe there's a new restriction which old apps are not subject to. I could try making a new one myself.

Did you make a change regarding the issue of the limit of 100 ? :)

@Kperroch Yes, it is in the latest image now. But I don't think it will help this issue.

@styler2go
Copy link

styler2go commented Feb 24, 2023

Oh sorry it's the last one. Every other request ran through quickly and successfully

@styler2go Wow, very interesting! Seems like it's related to the Twitch API and/or the application you created in their dev console. But there aren't really a lot of options. Maybe there's a new restriction which old apps are not subject to. I could try making a new one myself.

I used a very old application from my Dev console. Should I try creating a new one?

Top one:
Screenshot_2023-02-24-23-17-13-37_f9ee0578fe1cc94de7482bd41accb329

@micahmo
Copy link
Owner

micahmo commented Feb 24, 2023

Something weird is going on. My application is from 2021 and works fine. But I just made a new one, and it returns the same 404 as yours.

@micahmo
Copy link
Owner

micahmo commented Feb 24, 2023

Well dang, I just found this note in the Twitch documentation.

This endpoint is deprecated and will be decommissioned on August 3, 2023. Access to this endpoint is limited to client IDs that have called the endpoint on or before February 17, 2023.

https://dev.twitch.tv/docs/api/reference/#get-users-follows

I will have to work up an alternative! Sorry about that to you both!

@styler2go
Copy link

styler2go commented Feb 24, 2023

I've just ran through some code and it seems like the twitchlib api will need an update to support this new endpoint:

https://dev.twitch.tv/docs/api/reference/#get-followed-channels

(I'll assume you already know that as you are faster in your own code 😄)

@micahmo
Copy link
Owner

micahmo commented Feb 25, 2023

I submitted an issue on TwitchLib, and they already responded.

TwitchLib/TwitchLib#1112

Even without TwitchLib, I could make a direct HTTP call. The problem is that this data (followers) is being moved behind user-specific authorization. Having a Client Secret and Client ID isn't enough. You'll need to authorize your instance of twitch2tuner to make API calls on your user's behalf. This is actually how I had written twitch2tuner to work back in the day, but then I realized at the time all the data I needed was public, so I just had to authenticate as an app. I'm afraid it might have to go back.

Another possibility is letting you specify the desired channels via configuration (env var). It's obviously not nearly as convenient as detecting everyone you follow, but it doesn't require any API changes.

@CyberPoison
Copy link

I also run in this issue, if i could help tell me 👍
Is there any app/script/docker image to get only twitch xml epg ? I'm looking for this now since some years, and not able to find something working at this moment, it was for emby but emby accept m3u :) but i run liveproxy to restream to my emby but the thing missing here is epg :( .

Do you have any idea @micahmo how i can get xml epg from twitch a script/docker/app, i have some tools to make a matching of channels = epg id / channels name, but i don't know a tool for the scraping / getting info over api .

@micahmo
Copy link
Owner

micahmo commented Feb 26, 2023

Hi all, I've published a new version which utilizes the new Twitch API endpoint. It's a bit more complicated to set up as it requires a user authentication. You can alternatively specify the channels you want via an env var. I've updated with README with instructions. Let me know if it works.

@CyberPoison Try the new version. It generate an EPG at the /epg.xml endpoint.

@CyberPoison
Copy link

Thanks,

I have tested and it works but it only gets 20 Followed Channels, perhaps i have some like 120 Channels followed, is there something i missed ?

@micahmo
Copy link
Owner

micahmo commented Feb 26, 2023

@CyberPoison, sorry about that! I failed to account for pagination in the new request. Can you try the latest?

@micahmo micahmo closed this as completed Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants