开发者

Embedly: Undefined index html

开发者 https://www.devze.com 2023-03-21 14:31 出处:网络
If you\'re familiar with the way embedly embeds articles, if gives you a nice thumbnail that when clicked, opens up a preview in a lightbox to the material that\'s being embedded. However, when I clic

If you're familiar with the way embedly embeds articles, if gives you a nice thumbnail that when clicked, opens up a preview in a lightbox to the material that's being embedded. However, when I click on the thumbnail for an embedded article (example), i get Notice: Undefined index: html in C:\wamp\www\art开发者_开发百科icledisplay.php on line 131

Line 131 is the print $oembed['html'] of case 'video':, shown below.

I'm guessing an article probably isn't supposed to get embedded as a video, and I'm clearly missing some code from Embedly's PHP github.

Could anyone that's worked with Embedly before help me figure out how to resolve this? Thank you.

switch($oembed['type']) {
        case 'photo':
            print '<div class="embed-content"><div class="embed-wrapper">';
            if (!array_key_exists('title', $oembed)) {
              ?><img src="<?php echo $oembed['url'] ?>"></img><?php
            }
            else {
                ?><img src="<?php echo $oembed['url'] ?>" alt="<?php echo $oembed['title'] ?>"></img><?php
            }
            print '</div></div>';
            break;
        case 'link':
        case 'rich':
        case 'video':
            print '<div class="embed-content"><div class="embed-wrapper">';
            print $oembed['html'];
            print '</div></div>';
            break;
        case 'error':
        default:
        }


You should remove the "link" case from the switch statement, oEmbed only has html for "rich" and "video". The "link" type does not always have html, which cooresponds to your example link.

switch($oembed['type']) {
    case 'photo':
        print '<div class="embed-content"><div class="embed-wrapper">';
        if (!array_key_exists('title', $oembed)) {
          ?><img src="<?php echo $oembed['url'] ?>"></img><?php
        }
        else {
            ?><img src="<?php echo $oembed['url'] ?>" alt="<?php echo $oembed['title'] ?>"></img><?php
        }
        print '</div></div>';
        break;
    case 'rich':
    case 'video':
        print '<div class="embed-content"><div class="embed-wrapper">';
        print $oembed['html'];
        print '</div></div>';
        break;
    case 'error':
    default:
0

精彩评论

暂无评论...
验证码 换一张
取 消