First request an oath ID from twitch, replace the client_id and secret using your apps info. curl -X POST 'https://id.twitch.tv/oauth2/token?client_id=wadipzmhnzr5pchxzzngo2hufv6nut&client_secret=x2jq69uxye3496wql1oplq5v1kcl57&grant_type=client_credentials' Now request your channels host number, example: curl -H 'Client-ID: wadipzmhnzr5pchxzzngo2hufv6nut' -H 'Authorization: Bearer ezf7id5004m7gzz452770ha7y4oiw1' -X GET 'https://api.twitch.tv/helix/users?login=DJrunkie' Now we can check our channel to see if we are hosting someone or streaming. curl -H 'Client-ID: wadipzmhnzr5pchxzzngo2hufv6nut' -H 'Authorization: Bearer ezf7id5004m7gzz452770ha7y4oiw1' -X GET 'https://tmi.twitch.tv/hosts?include_logins=1&host=27941300' index.php

Give my friends on twitch a view!

news.php

Give my friends on twitch a view!

twitchcheck.sh #!/bin/bash #check for the iframe line from the file were updating, and cut out the text were interested in changing chosting=$(grep iframe /home/disc4lif/public_html/hostingexample/index.php | cut -f3 -d= | cut -f1 -d\&) #check the twitch api to see if this information has changed nhosting=$(curl -H 'Client-ID: wadipzmhnzr5pchxzzngo2hufv6nut' -H 'Authorization: Bearer ezf7id5004m7gzz452770ha7y4oiw1' -X GET 'https://tmi.twitch.tv/hosts?include_logins=1&host=27941300' | cut -f14 -d\") #we also need to check the twitch api to see if we are streaming. istream=$(curl -H 'Client-ID: wadipzmhnzr5pchxzzngo2hufv6nut' -H 'Authorization: Bearer ezf7id5004m7gzz452770ha7y4oiw1' -X GET 'https://tmi.twitch.tv/hosts?include_logins=1&host=27941300' | cut -f6 -d\") #our channel name cname=djrunkie #If were currently streaming, and the chosting value does not equal our twitch name, then update chosting with our twitch name in our files. Otherwise if chosting already = nhosting, or nhosting is blank then exit because either its already set, or were not hosting anyone currently. Otherwise chosting needs to be updated with nhosting. if [[ "$istream" = host_login ]] && [[ "$chosting" != "$cname" ]] then sed -i "s/channel=$chosting/channel=$cname/g" /home/disc4lif/public_html/hostingexample/index.php sed -i "s/channel=$chosting/channel=$cname/g" /home/disc4lif/public_html/hostingexample/news.php elif [[ "$chosting" = "$nhosting" ]] || [[ "$nhosting" = '' ]] then echo "They're the same dude, or nhosting was blank" exit else sed -i "s/channel=$chosting/channel=$nhosting/g" /home/disc4lif/public_html/hostingexample/index.php sed -i "s/channel=$chosting/channel=$nhosting/g" /home/disc4lif/public_html/hostingexample/news.php fi newtoken.sh #!/bin/bash #get the current token from the twitchcheck script we just created ctoken=$(grep -m 1 'Bearer' /home/disc4lif/twitchcheck.sh | cut -f4 -d\' | awk {'print $3'}) #get a new token using our client_id and client_secret from our twitch application ntoken=$(curl -X POST 'https://id.twitch.tv/oauth2/token?client_id=wadipzmhnzr5pchxzzngo2hufv6nut&client_secret=x2jq69uxye3496wql1oplq5v1kcl57&grant_type=client_credentials' | cut -f4 -d\") #replace the current token with the new token sed -i "s/$ctoken/$ntoken/g" /home/disc4lif/twitchcheck.sh #create a cronjob to run these automatically. The first script every 5 minutes, the second once a month. crontab -e */5 * * * * sh /home/disc4lif/twitchcheck.sh * 2 7 */1 * sh /home/disc4lif/newtoken.sh