Hello,
I need to recover email and username.
For the moment with url: “https://id.twitch.tv/oauth2/token ”
I have “access_token”, “expires_in”, “refresh_token”, “scope”: [“user_read”], “token_type”: “bearer”.
however following in my code I use url: “https://api.twitch.tv/helix/users ”
I got: {“error”: “Unauthorized”, “status”: 401, “message”: “OAuth token is missing”}
$validate_token is ‘access_token’
$ch = curl_init ();
$url = 'https://api.twitch.tv/helix/users';
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt ($ch, CURLOPT_HTTPHEADER, array (
'Authorization: Bearer'. $validate_token,
'Client-ID:'. $clientID
));
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, false);
$response = curl_exec ($ ch);
echo $response;
curl_close ($ ch);
With reqbin i got a good response json but with my website i don’t got.
curl_setopt ($ch, CURLOPT_HTTPHEADER, array (
'Authorization: Bearer'. $validate_token,
'Client-ID:'. $clientID
));
should be
curl_setopt ($ch, CURLOPT_HTTPHEADER, array (
'Authorization: Bearer '. $validate_token,
'Client-ID:'. $clientID
));
You were missing the space after Bearer and before the token
Its not a solution,
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '. $validate_token,
'Client-ID: '. $clientID
));
I add a space in 'Authorization: Bearer ’ and 'Client-ID: ’
again : {“error”:“Unauthorized”,“status”:401,“message”:“OAuth token is missing”}
And you checked that $validate_token
contains the token?
I don’t see any other problem with your code
This doesn’t tell me if $validate_token
is available to your first bit of code.
You may have wrapped the first bit in a function and not made the token available inside that function.
So might be easier to show all your code rather than parts of your code
Theres your problem
CURLOPT_RETURNTRANSFER => false
and/or
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
This should be true
for both requests.
Other wise
$response = curl_exec($ch);
Contains nothing useful
https://www.php.net/curl_setopt
TRUE
to return the transfer as a string of the return value of curl_exec() instead of outputting it directly.
I just didn’t clock it in your original post
Nice !
Its good thanks you im very stupid
system
Closed
June 24, 2020, 6:19pm
10
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.