888Owl
April 30, 2018, 7:14am
1
i want to use this ** https://api.twitch.tv/helix/streams** endpoint and i wasted about two days setting up authentication before re-re-reading about it and seeing no authentication required and was wondering for the endpoint the only authent i need is to put my id in the header of my ajax and i really don’t understand how to do that and was wondering if anyone had advice or could help,
i appreciate anything
You can refer to the example calls to the right of the docs here
Failing that provide the code you are using and we can see what needs to be fixed
888Owl
April 30, 2018, 7:39am
3
thank you for that,
i dont really know how to use curl, so i have been using ajax which i am sort of comfortable with for this purpose…
and im pretty sure it needs my client id and my secret which i tried using the ajax built in methods{username:name, password:password} would that not be the right way to go?
ill post up my code in just a second
888Owl
April 30, 2018, 7:43am
4
$(document).ready(function(){
//make sure jquery library is working
$(“p”).append(“hello world”);
//declare stream array
var twitchers=[“dmbrandon”,“MedryBW”,“ESL_SC2”, “OgamingSC2”, “cretetion”, “freecodecamp”, “storbeck”, “habathcx”, “RobotCaleb”, “noobs2ninjas”];
//declare endpoint
var endPoint=“https://api.twitch.tv/helix/streams?user_id= ”+twitchers;
//declare get method
$.ajax({
//headers:"user-id:my-twitch-id ",
url:endPoint,
dataType: ‘json’,
async:false,
type:‘GET’,
username:“my-twitch-id ”,
password:“my-twitch-secret ”,
success: function(data){
console.log(data);
},
error:function(error){
console.log("Your ERROR is: "+ error);
}
});
});
Your twitchers
contains user_login
s, not user_id
s.
The secret is only needed in the authorization flow (hitting id.twitch.tv ), and only in code running on a server, never in a browser .
Using ajax, the client-id header is sent as
headers: { 'client-id': your_client_id }
1 Like
var twitchers=[“dmbrandon”,“MedryBW”,“ESL_SC2”, “OgamingSC2”, “cretetion”, “freecodecamp”, “storbeck”, “habathcx”, “RobotCaleb”, “noobs2ninjas”];
//declare endpoint
var endPoint=“https://api.twitch.tv/helix/streams?user_id=”+twitchers;
should/could be
var twitchers=[“dmbrandon”,“MedryBW”,“ESL_SC2”, “OgamingSC2”, “cretetion”, “freecodecamp”, “storbeck”, “habathcx”, “RobotCaleb”, “noobs2ninjas”];
//declare endpoint
var endPoint="https://api.twitch.tv/helix/streams?user_login="+twitchers.join('&user_login=');
As you just pass multiple user_login
to the end point
https://api.twitch.tv/helix/streams?user_login=foo&user_login=bar
It’s not a CSV/object
(don’t direct copy paste the " got trashed)
1 Like
thank you both so much! its now displaying all live streamers so i can start building it from there!
system
Closed
May 31, 2018, 12:23am
8
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.