my understanding getting recent vods from a user id doesn’t need user authentication ?
I’ve tried multiple codes most of them errors but found this one in this form and its the only one not to give me errors I only want to get recent vods from a channel.
$client_id = ‘’;
$ch = curl_init(‘https://api.twitch.tv/helix/videos?user_id=whoever&first=50&sort=time&type=archive ’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Client-ID: ’ . $client_id,
));
$r = curl_exec($ch);
$i = curl_getinfo($ch);
curl_close($ch);
if ($i['http_code'] == 200) {
$videos = json_decode($r);
if (json_last_error() == JSON_ERROR_NONE) {
} else {
$error = 'An Error occurred at Parsing the videos response';
}
} else {
$error = 'An Error occurred fetching the videos';
}
am i missing anything?
Get Videos is public
So anyones token works, even with an app access token.
App access is generally used ofr server to server requests.
App access is also know as client credentials
Authentication
You are correct it doesn’t need a user token.
But Helix requires a token so you use the token needed for the endpoint as the documentation requires.
If it’s scoped: requires user token.
If it’s public: requires any token type.
Some endpoints are app access token only.
But all of helix requires a token.
TLDR : it doesn’t requirea user token, but it still requires a Token.
Ive added my client id so where am i going wrong?
im a bit of a newbie when it comes to api
im not getting any errors but it returns nothing
You didn’t generate a token.
So you’d generate/recall a token
Then use the token with your call to get videos
For example: since in PHP this would generat an app access token to use
Thank you i have now solved it! and working.
I’ve broke it again was working for a second now again it don’t display again
$client_id = '';
$ch = curl_init('https://api.twitch.tv/helix/videos?user_id=whoever&first=50&sort=time&type=archive');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/vnd.twitchtv.v5+json',
'Client-ID: ' . $client_id,
'Authorization: Bearer '
));
$r = curl_exec($ch);
$i = curl_getinfo($ch);
curl_close($ch);
if ($i['http_code'] == 200) {
$videos = json_decode($r);
if (json_last_error() == JSON_ERROR_NONE) {
echo 'success';
} else {
$error = 'An Error ocucred at Parsing the vidoes response';
}
} else {
$error = 'An Error occured fetching the vidoes';
}
ive removed my client id and Authorization: Bearer for this forum but the script does have it. ive been through the docs and honestly im stuck
‘Accept: application/vnd.twitchtv.v5+json’,
Don’t need this header thats for kraken, you could do
‘Accept: application/json’
however
If you get a non 200 the body will include an error message
Whats the error message?
hello
at first i was getting {“error”:“Unauthorized”,“status”:401,“message”:“OAuth token is missing”}"
so i added Authorization: Bearer and now im getting error 400
And whats the body message of the response.
It should providde a JSON blob that describes the error.
Using videos?user_id=whoever&first=50&sort=time&type=archive
as you put above the error response contaims a string that says that user_id is not a number: whoever
for example
Sorry for a late reply
that’s the thing i aint getting no error now I’ve got home its just blank empty not giving me any message at all now or any kind of response
$client_id = ';
$ch = curl_init('https://api.twitch.tv/helix/videos?user_id=VosanCo');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Client-ID: ' . $client_id,
'Authorization: Bearer '
));
$r = curl_exec($ch);
$i = curl_getinfo($ch);
curl_close($ch);
if ($i['http_code'] == 200) {
$videos = json_decode($r);
if (json_last_error() == JSON_ERROR_NONE) {
print_r($videos);
} else {
$error = 'An Error ocucred at Parsing the vidoes response';
}
} else {
$error = 'An Error occured fetching the vidoes';
}
Excuse brevity am on mobile
you leaked your app access token
you are using a username instead or a userID
you populate $error but don’t echo/print it. So if you error you don’t know
I didn’t even see that sorry I’ve edited it and will echo errors and get back to you and removed my app token Jesus didn’t even see that shall I get a new one now ?
Edit
I’ve deleted my app and created another one and got a new token so will get back to you soon
Oh you didn’t need to make a new app
Just revoke the token and make a new token
yeah i did that so i changed it userid now im not getting an error just this
stdClass Object ( [data] => Array ( ) [pagination] => stdClass Object ( ) ) stdClass Object ( [data] => Array ( ) [pagination] => stdClass Object ( ) )
all fixed thank you so much! working now and returning results
I do have one last question would it be the same for getting user id swap url for https://api.twitch.tv/helix/users?login=
Or is that a different process
Yeah any token works for login to id conversion on get users
It’s only a user token required if you want the user for that token
system
Closed
August 8, 2023, 8:01am
18
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.