PHPackages                             unl/oembedresource - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. unl/oembedresource

ActiveLibrary[API Development](/categories/api)

unl/oembedresource
==================

Generates an oEmbed resource to be returned to an oEmbed request

1.0.0(4y ago)1292MITPHPPHP &gt;=7.3

Since Jul 8Pushed 4y ago4 watchersCompare

[ Source](https://github.com/unl/oEmbedResource)[ Packagist](https://packagist.org/packages/unl/oembedresource)[ Docs](https://github.com/unl/oEmbedResource)[ RSS](/packages/unl-oembedresource/feed)WikiDiscussions 1.x.x Synced 1w ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

[![TravisCI Status](https://camo.githubusercontent.com/97c7801ce1983f97d4e32c4d6446504367b128863cfe1d8b117485f0e8ac1c65/68747470733a2f2f7472617669732d63692e636f6d2f756e6c2f6f456d6265645265736f757263652e7376673f6272616e63683d312e782e78)](https://camo.githubusercontent.com/97c7801ce1983f97d4e32c4d6446504367b128863cfe1d8b117485f0e8ac1c65/68747470733a2f2f7472617669732d63692e636f6d2f756e6c2f6f456d6265645265736f757263652e7376673f6272616e63683d312e782e78)

oEmbed Resource
===============

[](#oembed-resource)

The `OembedResource` class generates JSON and XML resource payloads to return to oEmbed requests.

Install
-------

[](#install)

Install this package via composer:

```
composer require unl/oembedresource
```

Usage
-----

[](#usage)

```
use unl\OembedResource\OembedResource;
...
// Instantiate OembedResource class and add oEmbed parameters as properties.
$resource = new OembedResource('video');
$resource->setTitle('My Video');
$resource->setHtml('');
$resource->setWidth(940);
$resource->setHeight(549);
$resource_payload = $resource->generate();

// At this point, return an HTTP response.
header('Content-Type: application/json+oembed');
echo $resource_payload;
die();
```

Instantiate OembedResource class
--------------------------------

[](#instantiate-oembedresource-class)

The constructor requires a 'type' parameter for the type of resource being requested. Valid types include: `photo`, `video`, `link`, and `rich`.

```
$resource = new OembedResource('video');
```

Add oEmbed parameters as class properties
-----------------------------------------

[](#add-oembed-parameters-as-class-properties)

The class provides GETTER and SETTER methods:

```
// Type
// Required to instantiate class.
$type= $resource->getType();

// Title (string)
// Optional
$resource->setTitle('My Video');
$title = $resource->getTitle();

// Author Name (string)
// Optional
$resource->setAuthorName('Mark Twain');
$author_name = $resource->getAuthorName();

// Author URL (string)
// Optional
$resource->setAuthorUrl('https://www.my-oembed-provider-service.com/mtwain');
$author_url = $resource->getAuthorUrl();

// Provider Name (string)
// Optional
$resource->setProviderName('My oEmbed Provider');
$provider_name = $resource->getProviderName();

// Provider URL (string)
// Optional
$resource->setProviderUrl('https://www.my-oembed-provider-service.com');
$provider_url = $resource->getProviderUrl();

// Cache Age (int)
// Optional
$resource->setCacheAge(86400);
$cache_age = $resource->getCacheAge();

// Thumbnail URL (string)
// Optional (If any thumbnail oEmbed parameter is set, then all three must be set.)
$resource->setThumbnailUrl('https://www.my-oembed-provider-service.com/video/123/thumbnail.jpg');
$thumbnail_url = $resource->getThumbnailUrl();

// Thumbnail Width (int)
// Optional (If any thumbnail oEmbed parameter is set, then all three must be set.)
$resource->setThumbnailWidth(940);
$thumbnail_width = $resource->getThumbnailWidth();

// Thumbnail Height (int)
// Optional (If any thumbnail oEmbed parameter is set, then all three must be set.)
$resource->setThumbnailHeight(549);
$thumbnail_height = $resource->getThumbnailHeight();

// URL (string)
// Required for 'photo' resources.
$resource->setUrl('https://www.my-oembed-provider-service.com/photo/123.jpg');
$url = $resource->getUrl();

// Width (int)
// Required for 'photo', 'video', and 'rich' resources.
$resource->setWidth(940);
$width = $resource->getWidth();

// Height (int)
// Required for 'photo', 'video', and 'rich' resources.
$resource->setHeight(940);
$height = $resource->getHeight();

// HTML (string)
// Required for 'video' and 'rich' resources.
$resource->setHtml('');
$html = $resource->getHtml();
```

Generate response payload
-------------------------

[](#generate-response-payload)

To convert the `OembedResource` object into a JSON or XML string, call the `generate()` method:

```
// By default, JSON is generated.
$json_payload = $resource->generate();
$json_payload = $resource->generate('json');

// XML can also be generated.
$xml_payload = $resource->generate('xml');
```

Send the response to the client
-------------------------------

[](#send-the-response-to-the-client)

One the payload string has been generated, it's up to the instantiating code to return an HTTP response to the client. Consult your PHP framework docs (Laravel, Symfony, etc.).

A quick and dirty return is provided below for JSON and XML:

```
// Send JSON response.
$resource_payload = $resource->generate();
header('Content-Type: application/json+oembed');
echo $resource_payload;
die();
```

```
// Send XML response.
$resource_payload = $resource->generate('xml');
header('Content-Type: text/xml+oembed');
echo $resource_payload;
die();
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1774d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e031eb579cc69ba56d0e76d472cfe212a93ea180852d524e37ab12f0d12b02b?d=identicon)[macburgee1](/maintainers/macburgee1)

---

Top Contributors

[![macburgee1](https://avatars.githubusercontent.com/u/1521132?v=4)](https://github.com/macburgee1 "macburgee1 (7 commits)")

---

Tags

resourceoembed

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/unl-oembedresource/health.svg)

```
[![Health](https://phpackages.com/badges/unl-oembedresource/health.svg)](https://phpackages.com/packages/unl-oembedresource)
```

###  Alternatives

[wrav/oembed

A simple plugin to extract media information from websites, like youtube videos, twitter statuses or blog articles.

36205.0k3](/packages/wrav-oembed)[joskolenberg/laravel-jory

Create a flexible API for your Laravel application using json based queries.

4513.5k](/packages/joskolenberg-laravel-jory)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
