Follow button PUT Problem

Hey everyone!

I’m trying to create a follower button on the website i’m developing. However i’m a UI developer and at UX i mostly get stuck as i am now. The idea is to login to the site using twitch (Which works perfectly) and then add a button to the page to follow a specific user.

When i click the button at this moment i get redirected to my redirect_uri but without following the actual channel.

However i’m stuck at how to get the token perfectly. The code you see is what i have at the moment, but as i said it’s not my strongpoint.

			function follow(){
				POST https://api.twitch.tv/kraken/oauth2/token
				&client_id=INSERT
				&client_secret=INSERT
				&grant_type=INSERT
				&redirect_uri=http://twitchstreams.org/testpage.php
				&code=$_GET['code']
				curl -H 'Accept: application/vnd.twitchtv.v3+json' -H 'Authorization: OAuth '.$code \
				-X PUT https://api.twitch.tv/kraken/users/GETUSERNAME/follows/channels/masterwolfeh
			}

Where i wrote INSERT, i have those data just not having it public.
GETUSERNAME is where i don’t see how i can get the name in there of the connected user.

HTML

<button onclick="follow">test</button>

Is anyone able to help here?

With kind regards,
Celeste

Once again, what you have pasted here is not runnable code. It’s very hard to fix code when the code isn’t at least 50% correct. Here you seem to have mixed JS and BASH…

It seems like your goal is to have some JS function that follows a user. In this case I’d recommend using our JS SDK, and then your function would look something like this:

function follow (channel) {
  var success = function () {
    // This will run if the follow succeeds
  }
  var failure = function () {
    // This will run if the follow fails
  }
  Twitch.getStatus(function (error, status) {
    if (error) return failure();
    if (!status.authenticated) return failure();
    
    Twitch.api({method: 'user'}, function (error, user) {
      if (error) return failure();

      Twitch.api({verb: 'PUT', method: 'users/' + user.name + '/follows/channels/' + channel}, function (error, response) {
        if (error) return failure();

        success();
      });
    });
}

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