Get new follower notifications

Hello I am trying to get new follower data(id,name etc.) via javascript. I want to get notification about new follower from server. I do not know much I just wanted to do it myself. Looks like I did a mistake. Here is my code:

function getFollower(){

var xhttp = new XMLHttpRequest();

xhttp.open("POST", "https://api.twitch.tv/helix/webhooks/hub", true);

xhttp.setRequestHeader("Content-type", "application/json");
var jsondata;
xhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 202) {
//on doc that says it will send a 202 empty body and yes it does
        jsondata = JSON.stringify(xhttp.responseText);
        console.log(jsondata);
    document.getElementById("widget").innerHTML = "test "+jsondata;
  }
  if (this.readyState == 4 && this.status == 400) {

    document.getElementById("widget").innerHTML = this.responseText;

  }
};


xhttp.setRequestHeader("Client-ID", "xxxxxxxxxxxxxxxxxxxxxxxxxx"); // mysecret

var data = JSON.stringify({"hub.mode":"subscribe","hub.topic":"https://api.twitch.tv/helix/users/follows?to_id=XXXXXXX&first=1","hub.callback":"http://100.xx.xx.xx:port/savetodb.php"});

xhttp.send(data);
}

“http :// 100.xx.xx.xx:port” is ip and I can access it anywhere. PHP page saves something to MYSQL db to see if that works. What am I missing here ?

Have you correctly set up a GET handler on your callback URL to deal with the hub.challenge?

No, I have no hub.challenge how should I prepare that ?

Webhooks work as follows

  1. You POST to make a sub, twitch replies 202
  2. Twitch sends a GET request to your Callback with a hub.challenge which in PHP presents as $_POST['hub_challenge'] iirc
  3. You echo back that challenge
  4. When data occurs Twitch POSTs back to your with JSON data in the body (file_get_contents on php://input)

if I get 202 that means, I will get response right however I do not get anything. My server listens a specific port which is not 80. But still I put my port to callback url. Is that a problem ?

Generally speaking you want to have your callback behind SSL/HTTPs, which requires a domain name (this may become a requirement at some point)

You seem to be using an IP address. So the normal url is

http://127.0.0.1:8001

For example.

protcol://ip_address:port

If it’s not working check that your Callback URL is web accessable and consult your server access/error logs and your firewall

You can use the Get Webhook Subscriptions endpoint to check if the subscription has been created or not https://dev.twitch.tv/docs/api/reference#get-webhook-subscriptions

If the subscription isn’t shown there, then there is an issue with your side of the subscription process.

Hey I saw your post on how to find what channels someone’s following or find out who someone is following could you help me with that?Here’s my email REMOVED If you could help me with that I would be forever grateful

It’s unwise to post you email publicly. I have removed it.

Please open a thread on the forums if you require help. Rather than jumping on someone elses thread. Especially when the issue you describe is totally unrelated to this thread

I’m sorry it’s just hard to get a hold of someone on these forums since you Can’t directly message them. Do you think twitch will add this feature in the future?

Please open another thread with the issue you are having. Please stop replying to this thread it is off topic to this thread.

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