Modify Channel Information API in PHP

I’m attempting to automate updating stream title and game because my streamer partner is struggling with remembering to do those. This is my first stab at doing it in PHP - here’s my code (minus extraneous var_dump bits):

$URD = curl_init();
$URDarray = array(   
    'title'=>'There be chaos up in here',

$URDinput = json_encode($URDarray);    
curl_setopt($URD, CURLOPT_URL, "");
curl_setopt($URD, CURLOPT_HTTPHEADER, array(  
    'Content-type: application/json',
    'Authorization: Bearer '.$authtoken,   
    'Client-ID: '.$clientid,         
curl_setopt($URD, CURLOPT_POST,true);
curl_setopt($UCR, CURLOPT_POSTFIELDS,$URDinput);
$URRdata = json_decode(curl_exec($URD),true);

The response I’m getting is:
array(3) {
string(11) “Bad Request”
string(61) “request must contain at least 1 channel property for updating”

Can some kind person please help me figure out what I’ve done wrong - the auth is working, the channel scope is good, so I’m sure there’s just some glaring errors in the way I’ve attempted to do the CURL patch stuff - the documentation is really really unhelpful for novice programmers!

curl_setopt($URD, CURLOPT_POST,true);

You delcare both POST and PATCH, so not sure which one succeeded. PATCH should of won. But it may not have done.

Also a typo here

curl_setopt($UCR, CURLOPT_POSTFIELDS,$URDinput);

should be

curl_setopt($URD, CURLOPT_POSTFIELDS,$URDinput);


1 Like

Well the typo certainly doesn’t help :rofl: :no_mouth: - thank you Barry - once again, for being so helpful! Unfortunately he’s gone offline so I can’t test it now so I will give it another try tomorrow!

Channel doesn’t need to be online to change the title/game!

Interesting - it’s pulled the channel information but it’s now giving me a NULL response to the query (after fixing the typo) - literally just ‘NULL’

If I take out curl_setopt($URD, CURLOPT_CUSTOMREQUEST, ‘PATCH’); I get a 404 not found

This Endpoint only accept’s PATCH’s

The response is a 204 No Content, so NULL is correct.
You should use curl_getinfo (PHP: curl_getinfo - Manual) to extract the HTTP response code.


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.