Andy
9
function create_app_access_token() {
// Twitch-Anmeldedaten
$clientId = 'XXX';
$clientSecret = 'XXX';
$tokenURL = 'https://id.twitch.tv/oauth2/token';
$params = array(
'client_id' => $clientId,
'client_secret' => $clientSecret,
'grant_type' => 'client_credentials'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $tokenURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($response, true);
if (isset($responseData['access_token'])) {
$accessToken = $responseData['access_token'];
return $accessToken;
} else {
return false;
}
}
function get_extension_stats() {
$accessToken = create_app_access_token();
$extensionID = 'XXX';
$apiURL = 'https://api.twitch.tv/helix/extensions/transactions';
$params = array(
'extension_id' => $extensionID
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiURL . '?' . http_build_query($params));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Client-ID: XXX',
'Authorization: Bearer ' . $accessToken,
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
// Antwort verarbeiten
$responseData = json_decode($response, true);
if (isset($responseData['data'])) {
$transactions = $responseData['data'];
var_dump($transactions);
} else {
var_dump($responseData);
}
}