Twitch api cURL php return Invalid OAuth token error

No, modify your existing script as needed. The GitHub is an example that demonstrates how to get a token.

As an example this can example be run as a command line script.

If you don’t have a command line/ssh on your hosting then you don’t have a command line to use. So your current script is running as a web page I guess, so you can put the code there inside your webpage