Likes of My Game

Hi, what i’m trying to achieve is to get the likes from my game via HTTP Service and a Web Service
but my issue is i keep on getting the wrong number

How could i fix it? I’m using this free use code

const express = require('express');
const cors = require('cors');
const axios = require('axios');

const app = express();
app.use(cors());

const UNIVERSE_ID = '7728250854'; // Replace with your universeId

app.get('/likes', async (req, res) => {
    try {
        const url = `https://games.roblox.com/v1/games?universeIds=${UNIVERSE_ID}`;
        const response = await axios.get(url);

        console.log("Roblox API response data:", response.data);

        const gameData = response.data?.data?.[0];

        // Try thumbsUpCount, else favoritedCount, else 0
        const likes = gameData?.thumbsUpCount ?? gameData?.favoritedCount ?? 0;

        res.json({ likes });
    } catch (error) {
        console.error("Error fetching like count:", error);
        res.status(500).json({ error: 'Failed to fetch like count' });
    }
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
    console.log(`Server running on port ${PORT}`);
});

as u can see it says 1/20 instead of 5/20 and 5 is the actual like count at the moment

The API you’re using is returning is the game favorites not the game likes. To get the game likes and dislikes you should use one of the two following APIs:

  1. https://games.roblox.com/v1/games/{universeId}/votes
    Easy to use API, returns id, upVotes(likes) and downVotes(dislikes)

  2. https://www.roblox.com/games/votingservice/{placeId}
    The API actually being used on the website. This returns a small html response you have to scrap to fetch the numbers. The small html is the likes/dislikes UI displayed on the website when viewing a game page.

2 Likes

Try using favoritesCount instead of favoritedCount

Ahh sry i already got it fixed but thank u for telling me

it would’ve been da solution tho

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.