Useful Custom APIs

It works! Thanks for the quick fix. There’s just a PHP notice when the token isn’t valid, specified or if the channel isn’t partnered (most likely it’s just about handling the Twitch API response that has an error property set), but it shouldn’t be an issue for this use senario. For reference here’s the notice:

Notice: Undefined index: message in /home/rtainc/www/api.rtainc.co/twitch/random-sub.php on line 4

Could I ask you which RNG function you are using for the random drawing? When I’ve coded a similar feature I’ve noticed that it wasn’t giving me that of a random drawing with array_rand (in the case of a quick succession of drawings… as I’ve added the ability to have more than 1 drawing to be done at the same time), so I’ve used mt_rand and coded my own simple mt_rand_array in the end.

Again, thanks for your reactivity :slight_smile:

For https://apis.rtainc.co/twitchbot/following?channel=CHANNEL&user=USER how can I make it to output Years, Months, Weeks, Days, & Seconds? Not just

As far as I know there is only one output format for the following command. Unless another gets added, then your out of luck. You’re more than welcome to create your own customapi.

1 Like

Edit: Scroll down for updated command.

1 Like

I’m looking for like "Animatedpanda has been following Channel for 1 year, 4 Months, 6 days.

You can append how many units of time you want to the new URL -

GET https://api.rtainc.co/twitch/followed-since?channel=kdwolf77&user=rtainc&units=6
5 months, 3 weeks, 2 days, 4 hours, 8 minutes, 53 seconds

Fixed!


By default it uses array_rand but you may now specify &method=mt_rand if you prefer its results.

1 Like

Very nice addition! Thank you.

@rtainc hey man can you make an API command to read “SOLO MMR” or “Hero winrate” for DOTA (Defense of the ancients) from this website? dotabuff.com/players/114827878 … if you already have something like this, please share :slight_smile:

Thanks for the suggestion! Unfortunately Dotabuff doesn’t provide any type of API, and I do not have any knowledge on how DotA stats are stored, so I am (at current) unable to do so. If you do end up finding any type of DotA Stats site with links to an API, I’ll be happy to implement it for a Nightbot command. :smile:

Just read your message. Thank you so much. Exactly what I was looking for.

Hi can anyone please make a customapi to make nightbot answer like clever bot like !addcom nightbot $(customapi $(query)) so you could say Nightbot hello and nightbot would respond based on what you said if someone could do this I will be in debt to them forever

I mean you could use:

and make the responses yourself.

I have no idea what Cleverbot does or says. So this is the best I can offer.

2 Likes

Thanks I’ll try clever bot is like an ai that replies to you based on what you said

It’s not what I’m looking for but thanks!

I’m having a problem with the Sub Age command, its saying someone has been subbed for 2 months when they have been subbed for 9 in a row.

Please PM me the Twitch token and the subscriber’s Twitch name so I can look into it. Thanks!

There was one of these at some point that I saw, however it seems the site has gone down. I’d love to make one of these for fun some day but unfortunately right now I don’t have the time as it’s such an extensive project. If I do end up making one I’ll tag you.

2 Likes

Yea I saw that sadly the site is down. Thanks a lot the command isn’t needed straight away if you ever create the command for fun in a couple of months or a couple of years I’ll be very thankful

I am trying to integrate the latest subscriber name in my HTML5 overlay through Javascript/AJAX and looking for an API to retrieve the latest/newest subscriber rather than a random subscriber any possibility to realize this?

Curious thing is when I try to retrieve the information through javascript/AJAX and set the datatype to any other acceptable type than json it returns nothing in the .done() section. However if I set json as expected datatype it returns the data I need (msg.responseText) however it always triggers the .fail() of the AJAX call.

$.ajax({
  type: "GET",
  url: "https://apis.rtainc.co/twitchbot/randomsub",
  data: {
    "token": "<MY TOKEN>",
  },
  crossDomain: true,
  dataType: "json",
})
  .done( function(msg){
    console.log("done");
    console.log(msg);
  })
  .fail( function(msg){
    console.log("fail");
    console.log(msg);
  });

I’d recommend using Twitch’s API directly for this, which supports CORS requests.

$.get("https://api.twitch.tv/kraken/channels/<CHANNEL>/subscriptions?direction=DESC&limit=1&oauth_token=<TOKEN>").done(function(sub) {
    console.log(data.subscriptions[0].created_at); // "2015-10-14T19:56:06Z"
    console.log(data.subscriptions[0].user.display_name); // "rtainc"
});
1 Like

Yea I have looked into that of course but my problem was the oauth_token that I could not generate myself just for my own HTML overlay. But I am using now the token generated by the link above the main post and it works, so thanks :smiley:

Any idea how long the oauth_token stays valid before I have to change it in my overlay code?