How to follow a channel on behalf of a user?

I would like to know how I could go in following a channel on behalf of another user?
I have been reading the documentation and from what I understood we need the code returned by Twitch in order to set the token to make requests on behalf of the user. The problem is that this code is handled by my application in order to link the Twitch account with my web application account.

What I would like to do is:

User is displayed with “Follow channel x” -> User clicks button to follow channel -> in the backend it makes the request on behalf of the user

I’m sorry if it seems a trivial question but I have been strugling to understand if that is possible.

Thank you for your time.

One way would be for them to authorize your application when they go to your web front end and generate a User Access Token with the user_follows_edit scope. Then you can follow a channel on their behalf using the generated token.

Thank for you answer Six. I have read the documentation but one thing I dont understand is: I have a method called handleTwitchCallback. This method only does is to handle the callback from Twitch but what Im trying to do is: I would like to have an Ajax request on behalf of the user to follow channel x. How am I going to get the code for beeing able to create the access token?

Here is a mock up of my methods:

function redirectToTwitch()
function handleTwichCallback() -> this method just register the user in my webapp and store the twitch id
function followChannel() -> I would like this method to perform the follow action on behalf of the user

My problem here is: I cant seem to redirect the user to the Twitch application because it is an AJax call. Any ideas?

Once again, thank you for your time and the answer

If your application is web based with a url, then you can redirect them there. If it’s an actual computer application, then there isn’t a way to redirect them back. There are others on here that have experience with Ajax, they might better suited to help you with your redirect question.

As far as generating the token, You would just make a rest request to the url listed in the link I posted above while filling out the required parameters. From there, you can extract the token from the response. How do to that programmatically, I’m unsure, as I have never really done anything web based. I’ve only ever manually copied the token after generating it.

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