Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

opengraph-react

Package Overview
Dependencies
Maintainers
0
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

opengraph-react

Handy React components for www.opengraph.io

  • 2.4.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
52
decreased by-24.64%
Maintainers
0
Weekly downloads
 
Created
Source

Opengraph-react

Opengraph React offers a collection of convenient React components designed to display website previews using data from https://opengraph.io. Also view how the site will be previewed on social media platforms like Facebook, Twitter, and LinkedIn.

The components are designed to be simple to use and can be customized to fit your needs. Explore a live demo at https://dashboard.opengraph.io/api-playground

Table of Contents

What is Opengraph.io?

OpenGraph.io client library for nodejs. Given a URL, the client will make a HTTP request to OpenGraph.io which will scrape the site for OpenGraph tags. If tags exist the tags will be returned to you.

Often times the appropriate tags will not exist and this is where OpenGraph.io shines. It will infer what the OpenGraph tags probably would be an return them to you as hybridGraph.

The hybridGraph results will always default to any OpenGraph tags that were found on the page. If only some tags were found, or none were, the missing tags will be inferred from the content on the page.

Installation

Simply install using npm:

npm install --save opengraph-react

Usage

Fetching Site Information with the OpenGraph.io API

This component is built to add simplicity to your project. It will fetch the site information from the OpenGraph.io API and display it in a card.

import OpengraphReactComponent from 'opengraph-react';

const ExampleComponent = () => {
  const website = 'https://www.opengraph.io';
  const appId = 'XXXXX'; //You're OpenGraph.io API Key goes here

  return (
    <OpengraphReactComponent
      site={website}
      appId={'Your opengraph.io api key goes here'}
    />
  );
};

Props

NameTypeDescription
sitestringWebsite that you want to load uri encoding is done for you so no need to encode it
appIdstringYour ApiKey for opengraph.io (you can get one at https://dashboard.opengraph.io)
dontMakeCallbooleanDefaults to false. Setting to true will allow you set your own information to be displayed.
resultsobjCustom result object passed when not making an API call.
loadercomponentA component to display while loading (ex a spinner) won't display anything by default
componentenumDefaults to 'large'.
onlyFetchbooleanIf this prop is supplied then no card will display, but instead the results from opengraph will be passed as props to the components children
acceptLangstringaccept lang header for request, defaults to "auto"
disableAutoProxybooleanTells OpenGraph.io to not use the Auto Proxy. Defaults to false.
fullRenderbooleanTell OpenGraph.io whether or not to use the Full Render feature.
useProxybooleanTell OpenGraph.io whether or not to attach a proxy to the request.
usePremiumbooleanTell OpenGraph.io whether or not to use the Premium Proxy feature.
useSuperiorbooleanTells OpenGraph.io whether or not to use the Superior Proxy feature
forceCacheUpdatebooleanIf this is supplied opengraph will not reply with cached result (defaults to false)
dontUseVideobooleanComponent will default to supplying a video player if it finds one in the results, pass this prop to override that behavior and just display an image like normal
dontUseProductbooleanComponent will not show product information.
debugbooleanDefaults to false. Want to see what results you're getting from the API? Just enable debug and look for 'RESULTS TO USE:' in the console.

Using Custom Site Results

If you don't want to make the call directly from the opengraph-react component, you can fetch the results from the API and then display the results.

import OpengraphReactComponent from 'opengraph-react';

const ExampleComponent = () => {
  const [results, setResults] = React.useState(null);
  
  const website = 'https://www.opengraph.io';
  const appId = 'XXXXX'; //You're OpenGraph.io API Key goes here

  React.useEffect(() => {
    const fetchResults = async () => {
      try {
        const response = await fetch(`https://opengraph.io/api/1.1/site/${encodeURIComponent(website)}?app_id=${appId}`);
        const data = await response.json();
        setResults(data);  
      } catch (error) {
        console.error(error);
      }
      
    };
    
    fetchResults();
  }, []);
  
  return (
    <OpengraphReactComponent
      dontMakeCall={true}
      results={results}
    />
  );
};

OpenGraph.io API Parameters

Below is a list of parameters and their descriptions, which can be passed to the OpenGraph.io API through the opengraph-react component.

ParameterRequiredExampleDescription
appIdyes-The API key for registered users. Create an account (no cc ever required) to receive your appId.
forceCacheUpdatenotrueThis will force our servers to pull a fresh version of the site being requested. By default, this value is false.
autoProxynotrueOpenGraph.io keeps a list of sites that require a proxy to be accessed. This will automatically route those requests through the necessary proxy.
fullRendernofalseThis will fully render the site using a chrome browser before parsing its contents. This is especially helpful for single page applications and JS redirects. This will slow down the time it takes to get a response by around 1.5 seconds.
useProxynofalseRoute your request through residential and mobile proxies to avoid bot detection. This will slow down requests 3-10 seconds and can cause requests to time out. NOTE: Proxies are a limited resource and expensive for our team maintain. Free accounts share a small pool of proxies. If you plan on using proxies often, paid accounts provide dedicated concurrent proxies for your account.
usePremiumnofalseThe Premium Proxy feature in our API allows you to leverage residential and mobile proxy pools for enhanced scraping performance.
useSuperiornofalseThe Superior Proxy feature is designed to tackle the most demanding scraping scenarios, allowing you to overcome the challenges posed by highly restrictive websites. By leveraging our superior proxy option, you can bypass bot detection mechanisms and access data from even the toughest sources.
acceptLangnoen-US,en;q=0.9 autoThis specifies the request language sent when requesting the URL. This is useful if you want to get the site for languages other than English. The default setting for this will return an English version of a page if it exists. Note: if you specify the value auto, the API will use the same language settings as your current request. For more information on what to supply for this field, please see: Accept-Language - MDN Web Docs

Available Components

Currently, there are 6 components available for use. They are as follows:

  • large
    • This will display a larger preview card. This is the default component.
  • small
    • This will display a smaller preview card.
  • x
    • This will display link previews in the same manner as X ( formerly known as Twitter )
  • facebook
    • This will display link previews in the same manner as Facebook
  • linkedin
    • This will display link previews in the same manner as LinkedIn

Keywords

FAQs

Package last updated on 08 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc