Git Product home page Git Product logo

Comments (26)

oscarotero avatar oscarotero commented on June 3, 2024

Hi.
I don't see any problem. It works fine in my computer and in the online demo: http://oscarotero.com/embed2/demo/index.php?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DkUylIQy-IgI
Maybe your computer has some requirements missing? (curl extension or any configuration that avoid create https requests?)

from embed.

rohitkhatri avatar rohitkhatri commented on June 3, 2024

It was working perfectly earlier, but now It's giving false don't know why ? But when I try to fetch vimeo,facebook,vine embed It does fetch. It's giving false for instagram and vimeo.

And yes curl is installed.

from embed.

oscarotero avatar oscarotero commented on June 3, 2024

Can you do a var_dump of $this->resut here?, so we can see the info about the curl request.

from embed.

rohitkhatri avatar rohitkhatri commented on June 3, 2024

I got the following output by doing var_dump

array(26) { ["url"]=> string(43) "https://www.youtube.com/watch?v=kUylIQy-IgI" ["content_type"]=> string(24) "text/html; charset=utf-8" ["http_code"]=> int(429) ["header_size"]=> int(465) ["request_size"]=> int(193) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(0.180564) ["namelookup_time"]=> float(0.004171) ["connect_time"]=> float(0.012106) ["pretransfer_time"]=> float(0.030642) ["size_upload"]=> float(0) ["size_download"]=> float(33043) ["speed_download"]=> float(182998) ["speed_upload"]=> float(0) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(0) ["starttransfer_time"]=> float(0.172199) ["redirect_time"]=> float(0) ["redirect_url"]=> string(0) "" ["primary_ip"]=> string(14) "173.194.33.129" ["certinfo"]=> array(0) { } ["primary_port"]=> int(443) ["local_ip"]=> string(13) "172.31.42.173" ["local_port"]=> int(42737) } 

from embed.

oscarotero avatar oscarotero commented on June 3, 2024

I see the http code result is 429, that means "Too many requests" (https://en.wikipedia.org/wiki/List_of_HTTP_status_codes)
Maybe you're executing to many requests to youtube and it blocks you temporary.

from embed.

rohitkhatri avatar rohitkhatri commented on June 3, 2024

Is there any solution for that ? And Instagram was not working, but now it's working fine.

Thanks for your help.

from embed.

oscarotero avatar oscarotero commented on June 3, 2024

I guess this depends of each service. Youtube and instagram may have a limited number of request in a time interval. Maybe executing the requests using different ips, but this is something out of the scope of this library.

from embed.

rohitkhatri avatar rohitkhatri commented on June 3, 2024

Thanks for your help.

from embed.

abelkbil avatar abelkbil commented on June 3, 2024

I too get false for youtube. All other works fine. Youtube works fine with localhost, But not in server. How to debug?

from embed.

rohitkhatri avatar rohitkhatri commented on June 3, 2024

@abelkbil do a var_dump of $this->resut here?, so we can see the info about the curl request.

from embed.

oscarotero avatar oscarotero commented on June 3, 2024

The latest version throws an exception instead simply returns true, so you can see why the curl request failed.

from embed.

rohitkhatri avatar rohitkhatri commented on June 3, 2024

I have changed my IP and have taken another ec2 instance with different ip but still it gives the same error even It's my first call to YouTube with this IP, any solution ?

from embed.

rohitkhatri avatar rohitkhatri commented on June 3, 2024

With updated library, It throws this error.

Fatal error: Uncaught exception 'Embed\Exceptions\InvalidUrlException' with message 'The url 'https://www.youtube.com/watch?v=PP1xn5wHtxE' returns the http code '429'' in /var/www/newsroom/public_html/app/inc/class/lib/Embed1/src/Embed.php:21 Stack trace: #0 /var/www/newsroom/public_html/app/test.php(3): Embed\Embed::create('https://www.you...') #1 {main} thrown in /var/www/newsroom/public_html/app/inc/class/lib/Embed1/src/Embed.php on line 21

from embed.

oscarotero avatar oscarotero commented on June 3, 2024

It's a bit odd. Can you try to change some curl parameters? Maybe the user agent or something like that.

Another aproach is to try to execute the curl request outside of the library:

$connection = curl_init();
curl_setopt_array($connection, [
    CURLOPT_RETURNTRANSFER => false,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_URL => 'https://www.youtube.com/watch?v=kUylIQy-IgI',
    CURLOPT_MAXREDIRS => 20,
    CURLOPT_CONNECTTIMEOUT => 10,
    CURLOPT_TIMEOUT => 10,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false,
    CURLOPT_ENCODING => '',
    CURLOPT_AUTOREFERER => true,
    CURLOPT_USERAGENT => 'Embed PHP Library',
    CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
]);

$content = curl_exec($connection);
var_dump(curl_getinfo($connection));

from embed.

rohitkhatri avatar rohitkhatri commented on June 3, 2024

When I tried curl request outside the library this content was shown.

from embed.

oscarotero avatar oscarotero commented on June 3, 2024

I don't know why this happens, seems like youtube detects the same network, no matter the specific ip.

from embed.

rohitkhatri avatar rohitkhatri commented on June 3, 2024

How can it be possible to detect a network instead of IP ? Have any idea ?

from embed.

oscarotero avatar oscarotero commented on June 3, 2024

From google's documentation

Google Search blocks IPs, IP ranges, and in some cases, whole ISPs, when a large percent of the traffic entering our networks is abusive.

Maybe your ip is in an ip range that it's blocked. I've googled this and they say the same in all results. I don't think much can be done, except wait for the overload goes away.

from embed.

rohitkhatri avatar rohitkhatri commented on June 3, 2024

You have been very supportive all the time, thank you so much for that. :-) I would try it with a totally different IP and let you know..!!

from embed.

cadavre avatar cadavre commented on June 3, 2024

Shouldn't we use dedicated methods to fetch thumbnails like https://developers.google.com/youtube/v3/docs/thumbnails ?

from embed.

oscarotero avatar oscarotero commented on June 3, 2024

I'm not using the youtube API because oembed is enought to get all needed data, not only thumbnail but also the author, title, embed code, etc. For example this So I don't see much benefits of using another http request to get the same information.

from embed.

cadavre avatar cadavre commented on June 3, 2024

So basically it's not server with installed Embed library requesting for YouTube thumbnail but oembed so why this problem exists?

I mean doing on server: CURL call to YouTube video gives 429 error, but calling http://www.youtube.com/oembed returns nice thumb url.

from embed.

oscarotero avatar oscarotero commented on June 3, 2024

Sorry but I don't understand what you mean.

from embed.

oscarotero avatar oscarotero commented on June 3, 2024

Embed always load the main url in the first place (for example https://www.youtube.com/watch?v=kUylIQy-IgI).
Then, it may execute other http requests depending of the page. For youtube videos, loads the data using the oembed API.
The problem here is youtube returns 429 error in the first call (the main url).

from embed.

cadavre avatar cadavre commented on June 3, 2024

So in this case I guess Embed should continue on error from main URL because it can fetch necessary data from other source (oembed). This will work for future services too. Is it possible?

from embed.

oscarotero avatar oscarotero commented on June 3, 2024

Embed doesn't work like that. The main url is loaded because many reasons:

  • To be sure the url exists and is valid (it must returns http code 200)
  • To resolve possible redirections (for url shorteners like bit.ly or even youtube has its own short url: https://youtu.be/)
  • To load data from the html (opengraph, twitter cards, etc)
  • A lot of services includes the url of the oembed service in the head. Youtube is one of these services. In the html code there is a link element like <link rel="alternate" type="application/json+oembed" href="http://www.youtube.com/oembed?format=json&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DkUylIQy-IgI">. So this library does not need to include a huge list of oembed endpoits for all possible services (hard to maintain) because they are taken from the html. It just need a small list with the services than does not provide this information in the html.

from embed.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.