script follower problem

maybe someone here can help me.
I’m trying to get a script to work.
the 2 part already works.
only the first one who should show me the number of followers doesn’t want to.
does anyone know where the error can be?

var counter = 0;
    changeFlapper();
    function changeFlapper(){
        if(counter == 0) {
            $.get({
            type: 'GET',
			headers: {"Client-ID": "########################"},
            url: 'https://api.twitch.tv/helix/users/follows?to_id=#########'
            success: function(data) {
                $('#row1').val(followsText + data).change();
                $('#row2').val("").change();
                $('#row3').val("").change();
                $('#row4').val("").change();
                return data;
            }
            });
            counter = 1;
        } else if (counter == 1){
            $.get({
            type: 'GET',
            headers: {"Client-ID": "########################"},
            url: 'https://api.twitch.tv/helix/users/follows?to_id=#########'
            success: function(data) {
                $('#row1').val(followsText).change();
                $('#row3').val(data.data[0].from_name).change();
                $('#row3').val(data.data[1].from_name).change();
                $('#row4').val(data.data[2].from_name).change();
                return data;
            }
            });
            counter = 0;
        }
    }

You only have a header of a Client-ID you have no token in your headers

All of helix requires a token, and you didn’t declare any.

This looks like front end code so you’d need to ask the user of the website to login with Twitch to provide a token to use

Example

https://barrycarlyon.github.io/twitch_misc/authentication/implicit_auth/

no, I just covered it up here.
that’s why there are only # in it

The lower part shows me the last 3 followers because it worked, but the upper one I can’t get to run, it should show me the current number of followers

Thats the clientID client ID’s are public
Authorization tokens are not public

You need two headers.

For example, using my GitHub Examples Client-ID:

headers: {
"Client-ID": "hozgh446gdilj5knsrsxxz8tahr3koz",
"Authorization": "Bearer XXXXXXX"
},

Then use the network tools part of the console inspector to debug the problem.
Since you are not looking for or tracking error,s just assuming success.

From the presented code it looks like a missing authorization header.

So I tried it.
but I can’t get any further.
Here you can see what he always shows me.

so I’m not getting any further.

So it still doesn’t show me my number of followers.

I will show the authorization as ### again

<script>
    //Change these vars to customize
    var time = 10000; //how often the overlay changes in milliseconds
    var followsText = "FOLLOWERS: "; //the text shown before the follow count
    var recentFollowsText = "RECENT FOLLOWERS: "; //the text shown before the recent followers list
	var Text = "RFOLLOWERS: "; //the text shown before the recent followers list
	
    //don't edit anything below here unless you know what you are doing.

    var counter = 0;
    changeFlapper();
    function changeFlapper(){
        if(counter == 0) {
            $.get({
            type: 'GET',
			headers: {"Client-ID": "hozgh446gdilj5knsrsxxz8tahr3koz","Authorization": "Bearer #################"},
            url: 'https://api.twitch.tv/helix/users/follows?from_id=440546277',
			success: function(data) {
                $('#row1').val(Text + data).change();
                $('#row2').val("").change();
                $('#row3').val("").change();
                $('#row4').val(Text + total).change();
                return data;
            }
            });
            counter = 1;
        } else if (counter == 1){
            $.get({
            type: 'GET',
            headers: {"Client-ID": "9uavest5z7knsvpbip19fxqkywxz3ec"},
            url: 'https://api.twitch.tv/helix/users/follows?to_id=440546277',
            success: function(data) {
                $('#row1').val(recentFollowsText).change();
                $('#row2').val(data.data[0].from_name).change();
                $('#row3').val(data.data[1].from_name).change();
                $('#row4').val(data.data[2].from_name).change();
                return data;
            }
            });
			counter = 0;
        }
    }
    const interval = setInterval(changeFlapper, time);
 
</script>
  1. You leaked your access token
  2. The second code block doens’t use a token. (when counter is 1) so its erroring and not processing the error
  3. The first code block (counter is 0) you feed the data object to be string concat with Text and never extract total from the API response to use on line 4

You’re also polling for the same data every 10 seconds, which is excessive. Due to caching you shouldn’t request the same data more frequently than once per min.

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