shweshi / OpenGraph

A Laravel package to fetch Open Graph data of a website.
https://opengraph.shashi.dev
MIT License
157 stars 29 forks source link
hacktoberfest laravel laravel-opengraph laravel-package metadata metadata-extraction opengraph opengraph-data opengraph-tags

Laravel OpenGraph

OpenGraph is a laravel package to fetch Open Graph metadata of a website/link.

Latest Version on Packagist Total Downloads Scrutinizer Code Quality StyleCI CodeFactor Build Status FOSSA Status

Features

Demo

  curl https://laravelopengraph.herokuapp.com/api/fetch?url=ogp.me&allMeta=true&language=en_GB

How to use Laravel OpenGraph

An article can be found on the medium blog: https://hackernoon.com/how-to-fetch-open-graph-metadata-in-laravel-2d5d674904d7

Documentation

https://opengraph.shashi.dev

Installation

Perform the following operations in order to use this package

composer require "shweshi/opengraph"

If you do not run Laravel 5.5 (or higher), then add the service provider in config/app.php:

If you do run the package on Laravel 5.5+, package auto-discovery takes care of the magic of adding the service provider.

Requirements

How to use

NOTE:

Anyone having problems getting metadata from social media sites please use the following user agent set on this example:

$opg_array = OpenGraph::fetch('URL', true, null, null, 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)');  

Exception Handling

The fetch() method, returns a FetchException with aditional data at failure.

      try {
          $data = OpenGraph::fetch($url, true);
      } catch (shweshi\OpenGraph\Exceptions\FetchException $e) {
          $message = $e->getMessage();
          $data = $e->getData();
      }

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING and CODE OF CONDUCT for details.

License

The MIT License (MIT). Please see License File for more information.

FOSSA Status

Support

Buy Me A Coffee

Happy coding!