I have been trying for hours to generate a clip programmatically but I do not understand the way twitch wants the request formatted. I am not used to CURL but I’m pretty sure I am sending the headers correctly.
All I get is “{“error”:“Unauthorized”,“status”:401,“message”:“Missing User OAUTH Token”}”
I have broadcaster_id in the URL because it doesn’t seem to read it anywhere else so I tried doing the token in the URL too but none of the GET names I’ve tried work. I can’t find any examples online of people using POST with PHP on anything that requires an oauth.
Any help would be great i am at the end of my rope here
$token = get_token();
$postRequest = array(
'token'=>$token
);
$postRequest= json_encode($postRequest);
$cURLConnection = curl_init('https://api.twitch.tv/helix/clips?broadcaster_id=44322889&access_token='.$token.'&token='.$token);
curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, $postRequest);
curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, array(
'client-id: sdf',
'Content-Type: application/json',
'Authorization: Bearer sdgf'
));
echo curl_exec($cURLConnection);
curl_close($cURLConnection);
The access token and client ID need to be specified as a header
Not a query string parameter
An example:
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Client-ID: ' . CLIENT_ID,
'Authorization: Bearer ' . $keys->access_token
));
you shouldn’t do BOTH like you have
Additionally, the error suggests you generated the wrong type of token
You need a response_type: code with the required scope attached
but made a response_type: client_credentials
Thanks for the reply! Do I not have it sending as a header? I took out the actual token but this line is supposed to send as a header is it not?
curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, array(
‘client-id: sdf’,
‘Content-Type: application/json’,
‘Authorization: Bearer sdgf’
));
See from here onwards I added whilst you were replying
Yeah I saw that I’ll take a look real quick thank you
Yeah I’ve not had coffee yet and read your title but not your code.
So your code looks correct (but you should removed the &access_token='.$token.'&token='.$token from the URL)
You’ve just got the wrong token type.
You generated a server to server token, which doesn’t represent a user.
So you need an oAuth flow (mini website) to obtain a user token with the clips:edit scope applied. So the API call can create a clip owned by the authenticating user.
Yeah I just had the redundancy in there in a desperate attempt to get it to see the token.
Thank you so much for your help. I thought since this is going to be a server->server thing I would need the other token. A user token didn’t make sense to me but it is working now so thank you so much for your time