Hey Niotron Community,
Have you ever wanted to implement Gamezop API in your app ?
For those unaware:
Gamezop is a plug-and-play gaming platform that any app or website can integrate to bring casual gaming for its users.
Over 5,000 products from more than 70 countries have integrated Gamezop and it’s an excellent way to improve user experiences.
To be able to use Gamezop API and/or the main Gamezop Portal, you need permission and an API Key from Gamezop.
We’ve developed API Implementation and providing it completely for free, with a beautiful design.
Contains:
PHP Code and AIA File
How to Setup:
1.Create a gamezop.php file into your server and copy-paste the code
-
Set the Web. URL with the actual link in your blocks
Just replace API_URL_GOES_HERE with your actual url… https://your_domain_name.com/gamezop.php
-
In gamezop.php just type your API ID and ensure the provided URL, from Gamezop, matches your $gamezopApiUrl
As per Gamezop recommendations, we cache the API response and load all games via ChromeView, rather than WebView.
You are free to modify the files, however you like.
Aia File
Gamezop.aia (4.1 KB)
Blocks
PHP File:
As I don’t have authorization to upload the actual script, here is the code that you can copy-paste and use it:
<?php
header('Cache-Control: public, max-age=86400'); // Cache for 24 hours
// Check if the cached API response exists
$cacheFilePath = 'gamezop_caches.json';
if (file_exists($cacheFilePath) && time() - filemtime($cacheFilePath) < 3600) {
// Serve Cache Response
echo file_get_contents($cacheFilePath);
http_response_code(200);
} else {
// Get raw posted data
$data = json_decode(@file_get_contents("php://input"));
// Replace with your API ID
$gamezopApiId = API_ID_GOES_HERE; // Replace with your actual value = example "2565"
if (!is_numeric($gamezopApiId) || $gamezopApiId <= 0) {
echo json_encode(['error' => 'Invalid Gamezop API ID']);
http_response_code(400);
exit();
}
// Sanitize and construct the API URL
$gamezopApiUrl = 'https://pub.gamezop.com/v3/games?id=' . urlencode($gamezopApiId);
$gamezopApiResponse = file_get_contents($gamezopApiUrl);
if ($gamezopApiResponse === false) {
echo json_encode(['error' => 'Error fetching games from Gamezop API']);
http_response_code(500);
exit();
}
$gamezopData = json_decode($gamezopApiResponse);
if (isset($gamezopData->games) && is_array($gamezopData->games) && count($gamezopData->games) > 0) {
$games = $gamezopData->games;
$html = '<div id="gamezop-offerwall">';
$html .= '<style>';
$html .= '
#gamezop-offerwall {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
}
.gamezop-game {
margin: 20px;
padding: 20px;
border: 1px solid #ccc;
border-radius: 10px;
width: 300px;
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.2);
}
.gamezop-game img {
width: 100%;
border-radius: 5px;
}
.gamezop-details {
margin-top: 10px;
font-size: 16px; /* Increased font size for the title */
text-align: center;
}
.gamezop-title {
font-weight: bold;
margin-bottom: 10px; /* Increased margin for the title */
}
.gamezop-description {
margin-bottom: 10px;
font-size: 14px;
}
.gamezop-button {
background-color: #2196F3; /* Blue background color */
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
border-radius: 20px;
width: 80%;
margin: auto;
text-align: center;
font-size: 16px;
}
.gamezop-plays {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 10px;
padding: 0 10px;
font-size: 12px;
color: #777;
}
';
$html .= '</style>';
// Display games
foreach ($games as $game) {
$html .= '<div class="gamezop-game" data-categories="' . implode(',', $game->categories->en) . '">';
$html .= '<img src="' . $game->assets->cover . '" alt="' . $game->name->en . '">';
$html .= '<div class="gamezop-details">';
$html .= '<p class="gamezop-title">' . $game->name->en . '</p>';
$html .= '<p class="gamezop-description">' . $game->description->en . '</p>';
$html .= '<a href="' . $game->url . '" class="gamezop-button" target="_blank">Play Now</a>';
$html .= '<div class="gamezop-plays">';
$html .= '<span>Plays: ' . number_format($game->gamePlays) . '</span>';
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
}
$html .= '</div>';
// Combine API response and processed HTML design
$cachedResponse = json_encode($html);
// Cache the API response and HTML design to a file
file_put_contents($cacheFilePath, $cachedResponse);
echo $cachedResponse;
http_response_code(200);
} else {
echo json_encode('No games available from Gamezop API');
http_response_code(404);
}
}
?>
We still haven’t tested the code on many screen-sized devices, but overall it should be well responsive.
If anyone finds bugs, kindly report them here