PHP code example of aternos / curseforge-api

1. Go to this page and download the library: Download aternos/curseforge-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aternos / curseforge-api example snippets



use Aternos\CurseForgeApi\Client\CurseForgeAPIClient;
$client = new CurseForgeAPIClient("api-key");

// set a user agent (recommended)
$client->setUserAgent('aternos/php-curseforge-api-example');

$games = $client->getGames();

foreach ($games as $game) {
    // like most other methods, this method returns a wrapper
    // you can use the getData() method to get the game data
    echo $game->getData()->getName() . PHP_EOL;
}

$games = $games->getNextPage();

foreach ($games as $game) {
    echo $game->getData()->getName() . PHP_EOL;
}

$game = $client->getGame(432);
echo $game->getData()->getSlug() . PHP_EOL;

$versionTypes = $client->getGameVersionTypes(432);
// or
$versionTypes = $game->getVersionTypes();

$versions = $client->getGameVersionTypeVersions(432, 68441);
// or
$versionType = $versionTypes[0];
$versions = $versionType->getVersions();

$versions = $client->getGameVersions(432);
// or
$versions = $game->getVersions();

$categoryClasses = $client->getCategories(432);
// or
$categoryClasses = $game->getCategories();

$categoryClasses = $client->getCategories(432, null, true);
// or
$categoryClasses = $game->getCategories(null, true);

$categories = $client->getCategories(432, 6);
// or
$categories = $game->getCategories(6);

$options = new ModSearchOptions(432); // the game ID is mods = $game->searchMods(); // options are optional here

$mods = $client->getFeaturedMods(432);
// or
$mods = $game->getFeaturedMods();

$featured = $mods->getFeatured();
$popular = $mods->getPopular();
$recentlyUpdated = $mods->getRecentlyUpdated();

$mod = $client->getMod(420561);

$mods = $client->getMods([420561, 278568, 715033]);

$description = $mod->getDescription();

$files = $mod->getFiles();

$options = new ModFilesOptions($mod->getData()->getId());
$options->setGameVersion("1.19.2");

use \Aternos\CurseForgeApi\Client\Options\ModSearch\ModLoaderType;
$options->setModLoaderType(ModLoaderType::FORGE);

$options = new ModFilesOptions(420561);
$options->setGameVersion("1.19.2");
$options->setModLoaderType(ModLoaderType::FORGE);
$files = $client->getModFiles($options);

$file = $client->getModFile(420561, 3787455);
// or
$files = $client->getModFiles([3787455, 3787456]);

$url = $file->getData()->getDownloadUrl();
// or if you don't already have the file object
$url = $client->getModFileDownloadUrl(420561, 3787455);

$file = $client->getModFile(420561, 3787455);
$fingerprint = $file->getFileFingerprint();

$fingerprint = CursedFingerprintHelper::getFingerprint("foo");

$fingerprint = CursedFingerprintHelper::getFingerprintFromFile("/path/to/file.jar");

$helper = new CursedFingerprintHelper($length);

while ($source->hasNextChunk()) {
    $helper->nextChunk($source->getNextChunk());
}

$fingerprint = $helper->finalize();

$files = $client->getFilesByFingerPrintMatches([1949504940, 1177254054]);
foreach ($files as $file) {
    echo $file->getFile()->getDisplayName() . PHP_EOL;
}

// Get Minecraft versions
$versions = $client->getMinecraftVersions();

// Get a specific version
$version = $client->getMinecraftVersion("1.19.2");

// Get mod loader versions
$modLoaders = $client->getMinecraftModLoaders();
$modLoaders = $client->getMinecraftModLoaders("1.19.2"); // optionally provide a Minecraft version
$modLoaders = $client->getMinecraftModLoaders(null, true); // show all loaders, including fabric

// get more information about a mod loader version
$version = $client->getMinecraftModLoader("forge-43.2.8");