You are getting API error because that’s what you’ve told it to do when $team is null. Because you’re looking directly at teams-> display_name you won’t see the error message returned from twitch, which is probably an unauthorized message, since you don’t appear to be passing a valid client id header.
Try echoing $data