Hello dear readers,
I have been struggling for days with a problem involving the TwitchAPI and SwiftUI.
Short Version of my problem:
I am unable to obtain a user token in iOS because Twitch only accepts the https protocol and not the Apple “myApp://” scheme, which means I can’t redirect back to my app.
Long Version of my Problem:
I am developing an app that requires data from Twitch, particularly information about followers. However, since there is a rate limit for API requests, I souldnt use my app token and need to obtain a user token instead. This can be easily generated using the following code:
let authURL = "https://id.twitch.tv/oauth2/authorize?client_id=\(CLIENT_ID)&redirect_uri=\(REDIRECT_URI)&response_type=code&scope=\(scopes.joined(separator: " "))"
.
Once the user logs in and accepts, I should be redirected to the app to fetch the token and continue working with it. The problem is that to redirect to my app, Xcode needs to use a URL scheme like “myApp://auth,” which TwitchAPI console does not accept for redirecting purposes. I have tried various solutions, including the OAuthSwift library on GitHub and setting up a webserver for redirecting the URL, but I have not been successful.
If anyone has any suggestions for how to solve this problem, I would greatly appreciate your input. Thank you in advance!