I GOT access_token but i don't know how to use it correctly

Result :
Got tokenstdClass Object ( [access_token] => xxxxxxxxxxxxx [expires_in] => 4852593 [token_type] => bearer )

How to use the acces token to get Streamdata in this code :

function Streamer ($x) {

$ch = curl_init('https://api.twitch.tv/helix/users?login=' . $x);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Client-ID: xxxxx'));
$data = curl_exec($ch);
$data = json_decode($data);



It Used to Work for me before but now i don’t know how to include the Acces token in my code , please Help me out , and thank you

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Client-ID: xxxxx'));


   curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Client-ID: xxxxx'
        'Authorization: Bearer yyyyyy'

yyyyy being your token

Parse error : syntax error, unexpected '‘Authorization: Bearer 2m4a77s’ (T_CONSTANT_ENCAPSED_STRING), expecting ‘)’ in

I Got this Error Sir .

Pre coffee code I missed a ,

   curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Client-ID: xxxxx',
        'Authorization: Bearer yyyyyy'

It Worked Now :smiley: Thank you So much for the help , and i have one more last question :
Is It possible to get Acces Token that never expires , so i don’t need to update every time on my website . Thank you again


All tokens expire.

So you should fetch a token, store it then auto refresh/get a new one when the token is near to expiration

Got tokenstdClass Object ( [access_token] => xxxxxxxxxx [expires_in] => 5675260 [token_type] => bearer )

Is the Expire value in secondes ?

Correct it’s in seconds.

You can use

To check a tokens current expires in time

Sorry for Asking a lot Sir but i have another Question :
On a Website for Each time i need to use an Api and also a Token , do you advice me Requesting a new Token each time or should i just refresh it as said in the twitch docs , which way in your opinion is more optimal .

Your should generate and store the token using a cron script
Store the token in a database/flat file/something.

Then your website/whatever will load the token from the database/flat file/something and use it as needed.

Saves wasting a cURL call to generate/check a token each time if you have a separate service managing it

Thank you So much Sir for your Time and informations . We are lucky to have you here :smiley:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.