mpratt / Embera

A Oembed consumer library, that gives you information about urls. It helps you replace urls to youtube or vimeo for example, with their html embed code. It has advanced features like offline support, responsive embeds and caching support.
MIT License
339 stars 59 forks source link

Not recognising Twitter or Flickr URLs (v1.9.2) #38

Closed lucanos closed 8 years ago

lucanos commented 8 years ago

I just found this (wonderful) library, and I am trying to allow for detection and replacement of Twitter and Flickr URLs through oEmbed.

My Code:

`require_once( 'inc/Embera/Autoload.php' );

$embera = new \Embera\Embera();

$text = 'http://vimeo.com/groups/shortfilms/videos/66185763 http://www.flickr.com/photos/bees/8597283706/in/photostream https://twitter.com/Interior/status/507185938620219395 http://youtube.com/watch?v=J---aiyznGQ';

echo $embera->autoEmbed( $text );`

My Output: image

Error is found regardless of whether the Twitter URL is prefixed with https or http.

Any help would be greatly appreciated.

mpratt commented 8 years ago

Hi @lucanos ,

I sadly cannot replicate the behavior. Your code returns:

<iframe src="https://player.vimeo.com/video/66185763" width="480" height="200" frameborder="0" title="The Silent Note" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<a data-flickr-embed="true" href="https://www.flickr.com/photos/bees/8597283706/" title="Durumu by ‮‭‬bees‬, on Flickr"><img src="https://farm9.staticflickr.com/8385/8597283706_7b51ea50b1_b.jpg" width="1024" height="723" alt="Durumu"></a><script async src="https://embedr.flickr.com/assets/client-code.js" charset="utf-8"></script>
<blockquote class="twitter-tweet"><p lang="en" dir="ltr">Happy 50th anniversary to the Wilderness Act! Here&#39;s a great wilderness photo from <a href="https://twitter.com/YosemiteNPS">@YosemiteNPS</a>. <a href="https://twitter.com/hashtag/Wilderness50?src=hash">#Wilderness50</a> <a href="http://t.co/HMhbyTg18X">pic.twitter.com/HMhbyTg18X</a></p>&mdash; US Dept of Interior (@Interior) <a href="https://twitter.com/Interior/status/507185938620219395">September 3, 2014</a></blockquote>
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
<iframe width="459" height="344" src="https://www.youtube.com/embed/J---aiyznGQ?feature=oembed" frameborder="0" allowfullscreen></iframe>

Which is the expected output.

However, the only way I get the same result as you is when I enable offline mode (via array('oembed' => false)). Since the library doesn't have offline support for twitter or flickr, the library returns the original url.

Are you using offline mode ? If you are, be sure to check the PROVIDERS.md file. The providers marked with an asterisk * have support for offline mode.

lucanos commented 8 years ago

I think the issue was/is curl trying to validate the SSL, and failing, which then meant there was no payload to process. Turning CURLOPT_SSL_VERIFYPEER to false seems to have fixed it.

mpratt commented 8 years ago

Hi @lucanos ! Thanks for the report.

Iv'e been trying to replicate the issue in different environments and it seems to work fine, Im just not able to replicate the issue.

So I would suggest to use the configuration array to pass that option to CURL, rather than "hard code" it in the library.

Something like this should work

    $config = array(
        'http' => array('curl' => array(CURLOPT_SSL_VERIFYPEER => false))
    );

    $embera = new \Embera\Embera($config);

If I get more reports of people with the same issue, I'll merge your PR, but for now I think using the config option is the better option here.

However, thanks for reporting it and for the PR!