WebService::Embedly - Perl interface to the Embedly API


Version 0.10


    use WebService::Embedly;
    use Ouch qw(:traditional);

    my $embedly = WebService::Embedly->new({ api_key => '',
                                             maxwidth => 500 });

    my $oembed_ref;
    my $e = try {
      $oembed_ref = $embedly->oembed('');

    if ( catch_all, $e) {
       warn("embedly api failed: ".$e);

    #made it here, everything good.
    my $embed_html = $oembed_ref->{html};


The WebService::Embedly is a class implementing for querying the web service. Prior to using this module you should go to and sign up for an api_key.

You can quickly try out the API by executing: ./sample/ --apikey

WebService::Embedly exposes three methods: oembed, preview, objectify. Each method has additional bits of metadata about the request URL. oembed method follows the oembed standard documented here

Refer to to learn more about the data that is returned for preview and objectify

Exception handling is used to expose failures. The Ouch module (:traditional) is used to handle try/catch blocks. See the Exception block below for all the possible catches. Example:

    my $e = try {
      $oembed_ref = $embedly->oembed('');

    if ( catch 500, $e) {
       #Server is down
    if ( catch 401, $e) {
       #Your API key has used all its credits
    elsif ( catch_all, $e) {
       #I hate the individual exception catching, lets get this over with it.

WebService::Embedly uses Mouse (lighter version of Moose) to handle its object management.


You must pass the api_key into the constructor:

    my $embedly = WebService::Embedly->new({ api_key => ''});

WebService::Embedly uses LWP::UserAgent to handle its web requests. You have the option to pass in your own LWP object in case of special requirements, like a proxy server:

    my $ua = LWP::UserAgent->new();
    $ua->proxy('http', '');

    my $embedly = WebService::Embedly->new({ api_key => '',
                                      ua => $ua

Optional Params

WebService::Embedly supports all optional parameters at the time of this writing Refer to the embedly documentation for the complete description. In the majority of cases you only need to pay attention to the maxwidth param. It is highly recommended to specify maxwidth since the embed html could overflow the space you provide for it.


This is the maximum width of the embed in pixels. maxwidth is used for scaling down embeds so they fit into a certain width. If the container for an embed is 500px you should pass maxwidth=500 in the query parameters.


This is the maximum height of the embed in pixels.


Will scale embeds type rich and video to the exact width that a developer specifies in pixels.

format (default: json)

The response format - Accepted values: (xml, json)


Returns a (jsonp) response format. The callback is the name of the javascript function to execute.


Will append the wmode value to the flash object. Possible values include window, opaque and transparent.

allowscripts (default: false)

By default Embedly does not return script embeds for jsonp requests. They just don’t work and cause lots of issues. In some cases, you may need the script tag for saving and displaying later. Accepted values: (true, false)

nostyle (default: false)

There are a number of embeds that Embedly has created including, Foursquare, and Formspring. These all have style elements and inline styles associated with them that make the embeds look good. Accepted values: (true, false)

autoplay (default: false)

This will tell the video/rich media to automatically play when the media is loaded. Accepted values: (true, false)

videosrc (default: false)

Either true Embedly will use the video_src meta or Open Graph tag to create a video object to embed. Accepted values: (true, false)


The words parameter has a default value of 50 and works by trying to split the description at the closest sentence to that word count.


chars is much simpler than words. Embedly will blindly truncate a description to the number of characters you specify adding ... at the end when needed.


All exceptions are thrown in terms of http status codes. Exceptions from the web service are passed through directly. For example and scroll down to view the Error Codes. For most situations you can simply do this:

    my $e = try {
      $oembed_ref = $embedly->oembed('');

    if ( catch_all, $e) {
       warn("embedly api failed: ".$e);
       #do something...




objectify; provide three different methods: oembed, preview, objectify depending on the amount of information/access you need each take the same parameters. However different data is returned depending on which method used.

There are three ways to call each method

Single URL

Fetch metadata about a single URL - call method with full url as a string

    $oembed_ref = $embedly->oembed('');

Multiple URLs

Fetch metadata about multiple URLs - call method with array ref of urls

   my @urls = qw(;
   $oembed_ref = $embedly->oembed(\@urls);

Extra Information

Fetch metadata about URL(s) and include additional query arguments - call methods with with hash ref of attributes

   my $query_ref = {

Can throw an exception (ouch) so wrap in an eval or use Ouch module and refer to its syntax


Jason Wieland


Please report any bugs or feature requests through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc WebService::Embedly

You can also look for information at:



Copyright 2012 Jason Wieland and 12engines LLC

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.