Hi, I have a php script and I’m trying to change title in the broadcast
I get the token with this:
$data = array(‘client_id’ => $client_id, ‘client_secret’ => $client_secret, ‘grant_type’ => ‘client_credentials’, ‘scope’ => ‘channel:manage:broadcast user:edit:broadcast’);
and this is the call:
curl_setopt($ch, CURLOPT_URL, ‘https://api.twitch.tv/helix/channels?broadcaster_id= ’ . $user_id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ‘PATCH’);
curl_setopt($ch, CURLOPT_POSTFIELDS, “{“title”:“NEWS”, “broadcaster_language”:“es”}”);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Client-ID: ’ . $client_id,
'Authorization: Bearer ’ . $token,
));
but i get:
“error”:“Bad Request”,“status”:400,“message”:“request must contain at least 1 channel property for updating”
What I need is to define the Title but also the “description”, please any advice will be good!
thanks
Federico
You are trying to use an App Access Token , which is not linked to a user. You must use the Implicit or Authorization Code Flow, not Client Credentials.
I could write a longer paragraph, but I already have here:
Introduction
So, you want to work with the Twitch API and you probably noticed that everything requires some sort of Authentication / Authorization to allow you to use it. This Post/Wiki aims to answer some FAQ about that procedure and help you along in your journey.
If you are already working with the API and are just struggling with Errors, scroll down to the Troubleshooting section.
If instead, you are new to the API entirely and want to learn more, just read on!
How to OAuth
If the Twitch…
Additionally, @Dkamps18 pointed out elsewhere that your call is missing a Content-Type
header. It should be set to application/json
for how you are sending the data. (That will be why it can’t find your parameters and complains about not having any parameters passed to the endpoint.)
1 Like
Ok Thanks, following your tips, now I have an URL that generate the code (token) with 2 scope
https://id.twitch.tv/oauth2/authorize?client_id=[client_id]&response_type=code&scope=channel:manage:broadcast%20channel:manage:videos&redirect_uri=http://localhost
I pass the token (code) in the curl:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.twitch.tv/helix/channels?broadcaster_id=' . $user_id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
$jsonData = array( 'title' => 'NEWS', 'broadcaster_language' => 'es');
$jsonDataEncoded = json_encode($jsonData);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Client-ID: ' . $client_id,
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
));
$result = curl_exec($ch);
but I have an “Unauthorized”,“status”:401,“message”:“Invalid OAuth token”
thanks for any help!
Federico
The code
is not a token
See Step 3
In our example, your user gets redirected to:
http://localhost/?code=394a8bc98028f39660e53025de824134fb46313
&scope=viewing_activity_read
&state=c3ab8aa609ea11e793ae92361f002671
3) On your server, get an access token by making this request:
POST https://id.twitch.tv/oauth2/token
?client_id=<your client ID>
&client_secret=<your client secret>
&code=<authorization code received above>
&grant_type=authorization_code
&redirect_uri=<your registered redirect URI>
or for PHP example:
// note: not testing the HTTP response codes,
// since we don't care too much as logging out
curl_close($ch);
}
session_destroy();
header('Location: /');
exit;
} else if (isset($_GET['code']) && $_GET['code']) {
// we have a code on the address line so lets parse and exchange
// validate the state/nonce
if (isset($_SESSION['nonce']) && isset($_GET['state']) && $_SESSION['nonce'] == $_GET['state']) {
// lets exchange the code for an access token
$ch = curl_init('https://id.twitch.tv/oauth2/token');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'client_id' => CLIENT_ID,
BarryCarlyon:
if (isset($_GET['code']) && $_GET['code']) {
// we have a code on the address line so lets parse and exchange
// validate the state/nonce
if (isset($_SESSION['nonce']) && isset($_GET['state']) && $_SESSION['nonce'] == $_GET['state']) {
// lets exchange the code for an access token
$ch = curl_init('https://id.twitch.tv/oauth2/token');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'client_id' => CLIENT_ID,
OK THANKS!!! PERFECT!
Seems is not possible to change the “live notification” via api…
Bye
system
Closed
April 19, 2021, 10:37pm
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.