# mod\_oembed

Source: https://zotonic.com/docs/1737/mod_oembed

URI: https://zotonic.com/id/1737

Language: en



Makes media [resources](/id/doc_glossary#term-resource) from embeddable URLs through the [OEmbed](http://www.oembed.com/) protocol.

This module, if activated, checks the pasted URLs in the *create media / page* dialog of the admin. It will show an embed option for services like YouTube, Vimeo or any other service which supports OEmbed.

A saved media resource has a thumbnail image which is downloaded from the OEmbed service and embedded in the resource. Furthermore, the resource’s medium record has an `oembed` field which contains the full JSON response of the request. The `oembed` field looks like this:

```erlang
"oembed": {
  "type": "video",
  "version": "1.0",
  "provider_name": "Vimeo",
  "provider_url": "http://vimeo.com/",
  "title": "Heli Filming Showreel",
  "author_name": "Hot Knees Media",
  "author_url": "http://vimeo.com/hotknees",
  "is_plus": "1",
  "html": "<iframe src=\"http://player.vimeo.com/video/20898411\" width=\"640\" height=\"362\" ...",
  "width": 640,
  "height": 362,
  "duration": 106,
  "description": "description..",
  "thumbnail_url": "http://b.vimeocdn.com/ts/138/106/138106290_640.jpg",
  "thumbnail_width": 640,
  "thumbnail_height": 362,
  "video_id": 20898411
}
```

So, to display the HTML of an OEmbedded medium, you would do the following in a template:

```erlang
{{ id.medium.html }}
```

The module also supports the use of the <a href="/id/doc_template_tag_tag_media" class="doc-reference doc-reference-tag"><code>tag#media</code></a> tag:

```erlang
{% media m.rsc[id].o.depiction.medium %}
```

Note however, that setting dimensions on this media tag is not supported for OEmbed, as the embed width/height is always taken from the provider.

Configuration options
---------------------

The following <a href="/id/doc_model_model_config" class="doc-reference doc-reference-model"><code>model#config</code></a> options are supported:

`mod_oembed.embedly_key`

The API key for Embedly. This configuration kan be added set in the admin via the menu **Auth -> External Services**.

`mod_oembed.maxwidth`

Requests the OEmbed service to return an HTML embed code with the requested maximum width. Defaults to 640.

`mod_oembed.maxheight`

Requests the OEmbed service to return an HTML embed code with the requested maximum height. Not set by default.

Accepted Events
---------------

This module handles the following notifier callbacks:

- `observe_media_import`: Expand supported oEmbed URLs into embeddable media metadata and resources.
- `observe_media_import_medium`: Import a embedded medium for a rsc\_import using `m_media:get`.
- `observe_media_stillimage`: Return the filename of a still image to be used for image tags using `oembed_admin:count_missing`.
- `observe_media_viewer`: Return the media viewer for the embedded video.
- `observe_rsc_update`: Check if the update contains video embed information using `z_acl:is_allowed`.

Delegate callbacks:

- `event/2` with `postback` messages: `fix_missing`.
- `event/2` with `submit` messages: `admin_oembed`.

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/1737?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/1737?language=en>)
