Ok after lots and lots of searching it turns out the spaces in the game names are an issue.
I solved this in php by using the function urlencode(string)
The following code works for games with spaces in such as Company of Heroes and Company of Heroes 2
function getTwitchGameDataByName($gameName){
// using new TWITCH API
try{
$url = "https://api.twitch.tv/helix/games?name=".urlencode($gameName);
$ch = curl_init();
$headers=array('Client-ID: '.TWITCH_API_ID);
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);
if (!empty($result)){
return json_decode($result, true);}
}
catch (Exception $ex){
return NULL;
}
}