Skip to content

Instantly share code, notes, and snippets.

@KristianP26
Last active July 16, 2024 17:02
Show Gist options
  • Select an option

  • Save KristianP26/c800b04e9cb0db316131ad5f88467202 to your computer and use it in GitHub Desktop.

Select an option

Save KristianP26/c800b04e9cb0db316131ad5f88467202 to your computer and use it in GitHub Desktop.
PHP Function for Retrieving Steam Workshop Item Subscriber Count
<?php
function getSteamWorkshopSubscriberCount($workshopItemId) {
$apiUrl = "https://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v1/";
$postData = [
"itemcount" => 1,
"publishedfileids[0]" => $workshopItemId,
];
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode != 200) {
error_log("Error fetching data from Steam Workshop API for item ID: $workshopItemId. HTTP code: $httpCode");
return "N/A";
}
$data = json_decode($response, true);
if (
isset($data['response']['publishedfiledetails']) &&
count($data['response']['publishedfiledetails']) > 0 &&
isset($data['response']['publishedfiledetails'][0]['subscriptions'])
) {
$subscriberCount = $data['response']['publishedfiledetails'][0]['subscriptions'];
return number_format($subscriberCount, 0, '.', ',');
} else {
error_log("Invalid or empty response from Steam Workshop API for item ID: $workshopItemId, Response: $response");
return "N/A";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment