cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

RE: Can Not Load Youtube Page To Get Source Code In Php

From: Liu Shan Shui <me_at_lx.sg>
Date: Thu, 30 Jul 2009 02:14:10 +0800

Hi Rick,

 

Your Canadian server is probably getting this response:

 

<?xml version='1.0' encoding='UTF-8'?><entry
xmlns='http://www.w3.org/2005/Atom' xmlns:app='http://purl.org/atom/app#'
xmlns:media='http://search.yahoo.com/mrss/'
xmlns:yt='http://gdata.youtube.com/schemas/2007'><id>http://gdata.youtube.co
m/feeds/api/videos/dxOpi41Jbys</id><published>2009-07-11T08:20:23.000Z</publ
ished><updated>2009-07-29T07:08:39.000Z</updated><app:control><app:draft>yes
</app:draft><yt:state name='restricted' reasonCode='requesterRegion'>This
video is not available in your region.</yt:state></app:control><category
scheme='http://schemas.google.com/g/2005#kind'
term='http://gdata.youtube.com/schemas/2007#video'/><title type='text'>MMA
Live: UFC 100 Weigh-In Special</title><link rel='alternate' type='text/html'
href='http://www.youtube.com/watch?v=dxOpi41Jbys'/><link rel='self'
type='application/atom+xml'
href='http://gdata.youtube.com/feeds/api/videos/dxOpi41Jbys'/><author><name>
ESPN</name><uri>http://gdata.youtube.com/feeds/api/users/espn</uri></author>
<media:group><media:category label='Sports'
scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Sports</media:
category><media:title type='plain'>MMA Live: UFC 100 Weigh-In
Special</media:title></media:group></entry>

 

Notice the "This video is not available in your region" error message (I got
that from my web browser, and I live in Singapore). And yes, if you tunnel
your request through a US proxy, it will probably work.

 

With regards,

Liu Shan Shui

me_at_lx.sg

"Life would be much easier if I had the source code." - Anonymous

 

From: curl-and-php-bounces_at_cool.haxx.se
[mailto:curl-and-php-bounces_at_cool.haxx.se] On Behalf Of Rick Estrada
Sent: Thursday, July 30, 2009 2:06 AM
To: curl with PHP
Subject: Re: Can Not Load Youtube Page To Get Source Code In Php

 

as i am in US my server is Canada.. so I will see if a US PROXY makes a
difference? i never used it so i see if i can get curl working with it..

yeah if i post the linke in my FF3 address bar

http://gdata.youtube.com/feeds/api/videos/dxOpi41Jbys

it opens a new tab with a temporary file that contains all the proper info
and shows FIREFOX BROWSER.

i just can not get the same result from the php page i made and curl?

----------------------------------------

REQUEST HEADER FROM FIREBUG

Host: gdata.youtube.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.12)
Gecko/2009070611 Firefox/3.0.12 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
If-Modified-Since: Wed, 29 Jul 2009 07:08:39 GMT

REQUEST RESPONSE FROM FIREBUG

X-GData-User-Country: US
Content-Type: application/atom+xml; charset=UTF-8
Expires: Wed, 29 Jul 2009 16:31:14 GMT
Date: Wed, 29 Jul 2009 17:18:51 GMT
Cache-Control: private, max-age=300, no-transform
Vary: *
GData-Version: 1.0
Content-Language: en-US
Last-Modified: Wed, 29 Jul 2009 07:08:39 GMT
Content-Encoding: gzip
X-Content-Type-Options: nosniff
Server: GFE/2.0
X-Moz-Is-Feed: 1

On Wed, Jul 29, 2009 at 10:49 AM, Liu Shan Shui <me_at_lx.sg> wrote:

Hi Rick,

 

Once again, it works fine here:

http://phpieceofcake.com/?66888746

 

I'm guessing that YouTube is blocking all non-US IPs from accessing *that
video* due to copyright issues (phpieceofcake.com and
sandbox.phpieceofcake.com are hosted on US servers; that's why it's
working). There's nothing wrong with cURL and your script, and as you have
said, your script works fine with other YouTube videos. So if you need your
script to work for that particular video and other copyright-restricted
videos, you'll have to either host it on a US server or send the request
through a US proxy.

 

As for how to use a proxy in cURL.there's quite a lot of information out
there:

http://lmgtfy.com/?q=How+to+use+cURL+with+a+proxy%3F

 

With regards,

Liu Shan Shui

me_at_lx.sg

"Life would be much easier if I had the source code." - Anonymous

 

From: curl-and-php-bounces_at_cool.haxx.se
[mailto:curl-and-php-bounces_at_cool.haxx.se] On Behalf Of Rick Estrada
Sent: Thursday, July 30, 2009 12:47 AM
To: curl with PHP
Subject: Re: Can Not Load Youtube Page To Get Source Code In Php

 

well i was trying to load the YOUTUBE API to get the XML and the DATA about
the Video

http://gdata.youtube.com/feeds/api/videos/dxOpi41Jbys

which it downloads in my browser fine but when i put on my server in the php
file it does not work and it returns me a different page...

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,
'http://gdata.youtube.com/feeds/api/videos/dxOpi41Jbys'
<http://gdata.youtube.com/feeds/api/videos/dxOpi41Jbys%27> );
  curl_setopt($ch, CURLOPT_HEADER, 1);
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT
5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $google_string = curl_exec($ch);
  curl_close($ch);
  $google_string = utf8_encode($google_string);
  print_r($google_string);

as i tested our page and it works correctly?

is there a way bypass IP-range restriction and see if thats the problem.
Thats would be weird as i can grab other videoid's no proble

i never tried the PROXY with curl so can that help test and see if that the
issue or something i can see in the headers or something?

On Wed, Jul 29, 2009 at 4:52 AM, Liu Shan Shui <me_at_lx.sg> wrote:

Hi Rick,

 

Your code works fine. It's probably some IP-range restriction for that video
on Youtube's side that's blocking your server.

http://phpieceofcake.com/?76868110

 

With regards,

Liu Shan Shui

me_at_lx.sg

"Life would be much easier if I had the source code." - Anonymous

 

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

-- 
Thanks,
Rick Estrada
Subfighter Mixed Martial Arts
760-908-9472
http://www.subfighter.tv

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2009-07-29