Get followers count

Hi community, I’m trying to get the total followers count by using the userID, as I saw in this post that you don’t need a scope to get only the total followers count, but I’m getting a 401 error: Get Follower count

Do I need an oauth token for this? Thanks in advance

This is my code:

useEffect(() => {
if (auth.twitch) {
const fetchTwitchToken = async () => {

              try {
                  const response = await clienteAxios.get(
                      'https://api.twitch.tv/helix/channels/followers?broadcaster_id=${ process.env.CLIENT_ID}',
                      {
                          headers: {
                              'Content-Type': 'application/x-www-form-urlencoded'
                          }
                      });


                  console.log(response.data)
                  
              } catch (error) {
                  console.log(error);

              }
          }

          fetchTwitchToken()
      }
  }, [auth])

You don’t need this as you are not POSTing

You have no Client-ID or Authorization header present

Whats the body message in the response

Yes, for the follower count only, any token will suffice

All of Helix requries an oAuth token

Thanks Barry. It says that the OAuth token is missing indeed.
Is there any way to get the token without using OAuth 2.0?
I am trying to add the feature for users on my website to input their Twitch accounts so that the total number of followers can be displayed as part of their profile data. I previously added the OAuth 2.0 option to obtain the userID, username, followers, etc. so they can add their accounts, but I would like to also add the total followers count to the public profile data page without having to go through the OAuth 2.0 process again. Is this possible somehow?

You would need an oAuth 2 App Access/Client Credentials token for the described use case

Any token works to get follow counts, you do not need to reauthenticate users for this

And if you have the users tokens from sign up you can use that
Or you can use a client credentials token

I see. But there is an expiration time for the token, right? Would it be a good practice to store the token in the database to avoid sending the request every time a user accesses the profile page? Or should I treat it as sensitive information?
I’m sorry for so many questions. I’ve been dealing with this for a while now so I just want to make sure I get it right

All tokens expire yes

If you want to do work on behalf of a user then you need to retain the users token generated during sign up (as well as their refresh token).

If you only need to access public data then you don’t need to retain the users access/refresh token no.

All tokens are sensitive.

It is ok to show the uses own token to the user.

But you should ensure you don’t leak user a’s token to user b and an app access token should never be leaked

1 Like

Great! That’s what I needed to know.
I’ve managed to get it done now.

Thanks a lot for your help Barry. Much appreciated! :pray:

1 Like

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