Truely, not being rude. We’re not here to write complete code for you or teach you a language.
Now that, that is over with. Just skimming over that php first you call authenticate and pass the returned url to the user to go to. Twitch will then return a “code” to your server/site and then you parse that out and then call get_access_token(code) api will then give you the access token. NOTE read the TOS in the readme on the github for twitch api. These “tokens” must be handled correctly. https://github.com/justintv/Twitch-API/blob/master/README.md#terms-of-service
After you get the token you then call authenticated_user(token) that will return the name object in the returned json file. You now have your username of the authenticated user. CONGRATS!