Twitch New API : URL (Helix)

2.1k views Asked by At

Recently, Twitch bring a new API version using new endpoints etc..

I was working on the V5, but I didn't use Curl command line, I work with URL.

So I decide to look at the references of the new version, trying for example to getting the followers and found this :

https://api.twitch.tv/helix/users/follows?to_id='user ID'

So I replace the user_ID by an id (mine and/or another) and get :

{
    "error":"Unauthorized",
    "status":401,"message":"Must provide a valid Client-ID or OAuth token"
}

When I was working on the V5, I was putting the client_id and the oauth at the end of the URL like this :

https://api.twitch.tv/kraken/channels/CHANNELNAME?client_id=xXxXxXxXxX&oauth_token=aaaabbbbccc111

And it was working, but in the new API, I already have a parameter so I added the client_id and token after with a & connector... But still have the same error.

I also try to put them before the to_id parameter, but same...

So my question is really stupid but anyone know the URL format on the new API?

1

There are 1 answers

1
Tigran Grigorian On

You should send your Client-ID in request's header now, not as a param in URL. But there's other problem with SSL/HTTPS in this case if you use curl. Here is a solution to your problem

DEFINE (TWITCH_API_KEY,'YOUR_KEY_HERE');
$url = 'https://api.twitch.tv/helix/streams/metadata';
$ch = curl_init();
$headers=['Client-ID: '.TWITCH_API_KEY];
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec ($ch);
curl_close ($ch);
echo $result;