#Discord Scraper Not Fetching Dynamic OGP/Twitter Card Data

3 messages · Page 1 of 1 (latest)

formal bronze
#

I have a issue with discord fetching the OGP values, when I use any other tool it shows valid OGP values however when I use the Discord Embed Visualiser it shows "Error Timed out" even though on other sites it takes little time to render it. My code fetches data from a API before placing it in the metadata tag. I think it may be a issue with discord's cache or something like that but am unaware of how to fix this as a discord preview is a reason I migrated to next.js.

What would help me most is some boilerplate code of fetching data from a api and setting it as metadata.

Discord Developer Portal

Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.

pseudo mountainBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

formal bronze
#

Code in 2 snippets as its too long for 1 large box also removed some stuff as its too long

import ArticleDetails from './displayData';

export const generateMetadata = async ({ params }) => {
  try {
    const response = await fetch(`API_ENDPOINT`, {
      method: 'POST',
      credentials: 'include',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ hash: params.hash }), 
    });

    if (!response.ok) {
      console.error(`Failed to fetch article data: ${response.status} - ${response.statusText}`);
      return {
        title: 'Page Not Found (404)',
        description: 'Page Not Found (404)',
        openGraph: {
          title: 'Page Not Found (404)',
          description: 'Page Not Found (404)',
          images: [
            {
              url: 'https://cdn.glitch.global/21a2d050-b3c7-4611-8e67-c6f3ae33f0df/favicon.png?v=1720056814938',
              width: 500,
              height: 500,
              alt: 'preview image',
            },
          ],
          url: 'https://website.com',
          type: 'website',
        },
        twitter: {
          card: 'summary_large_image',
          title: 'Page Not Found (404)',
          description: 'Page Not Found (404)',
          images: [
            'https://cdn.glitch.global/21a2d050-b3c7-4611-8e67-c6f3ae33f0df/favicon.png?v=1720056814938',
          ],
        },
      };
    }

```js
const data = await response.json();
    const entry = data.entry;
    console.log(entry);

   
};