title: PHP Script for Recent YouTube video using API v3
body: <p>A while ago I made a script that showed the most recent video on a channel by adding the username to an &amp;id=username in the URL. Recently, YouTube has began pushing people onto their new v3 of the API, and I'm unsure how I can update my code to get it to still work. The old code can be found below as a reference:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;link href='http://fonts.googleapis.com/css?family=Raleway:300' rel='stylesheet' type='text/css'&gt;
  &lt;script language="javascript" type="text/javascript"&gt;
  /*A very long java script to make the page responsive was removed from this snippet of code
   */
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php
  $feedURL = 'http://gdata.youtube.com/feeds/api/users/' . $_GET["id"] . '/uploads?max-results=1';
  
  $headers = get_headers($feedURL, 1);
  if ($headers[0] == 'HTTP/1.0 200 OK'): 
  $sxml = simplexml_load_file($feedURL);
  $i=0;
  foreach ($sxml-&gt;entry as $entry) {
        $media = $entry-&gt;children('media', true);
        $watch = (string)$media-&gt;group-&gt;player-&gt;attributes()-&gt;url;
        $thumbnail = (string)$media-&gt;group-&gt;thumbnail[0]-&gt;attributes()-&gt;url;
        $vid = (string)substr($thumbnail, 22, 11);
  ?&gt;
  &lt;style&gt;
  .videothumb {
       width:100%; }
  .videotitle {
       font-family: 'Raleway', Arial;
       color: #e10707;
       font-size: 20px;}
  a:link {
      text-decoration: none;
      color: #e10707;
  }
  
  a:visited {
      text-decoration: none;
      color: #e10707;
  }
  
  a:hover {
      text-decoration: none;
      color: #e10707;
  }
  
  a:active {
      text-decoration: none;
      color: #e10707;
  }
  &lt;/style&gt;
        &lt;div class="videoitem"&gt;
          &lt;!-- DEPRECATED &lt;div class="videothumb"&gt;&lt;a href="&lt;?php echo $watch; ?&gt;" class="watchvideo"&gt;&lt;img src="&lt;?php echo $thumbnail;?&gt;" alt="&lt;?php echo $media-&gt;group-&gt;title; ?&gt;" /&gt;&lt;/a&gt;&lt;/div&gt; --&gt;
          &lt;div class="videothumb"&gt;&lt;a href="&lt;?php echo $watch; ?&gt;" class="watchvideo"&gt;&lt;img src="&lt;?php echo 'https://img.youtube.com/vi/' . $vid . '/maxresdefault.jpg';?&gt;" alt="&lt;?php echo $media-&gt;group-&gt;title; ?&gt;" width="100%"/&gt;&lt;/a&gt;&lt;/div&gt;
          &lt;div class="videotitle"&gt;
              &lt;h3&gt;&lt;a href="&lt;?php echo $watch; ?&gt;" class="watchvideo"&gt;&lt;?php echo $media-&gt;group-&gt;title; ?&gt;&lt;/a&gt;&lt;/h3&gt;
          &lt;/div&gt;
  &lt;?php if ($_GET["debug"] == "1"): ?&gt;
          &lt;code&gt;Debug Information: &lt;br /&gt;
          Watch link: &lt;?php echo $watch; ?&gt; &lt;br /&gt;
          Video ID: &lt;?php echo $vid; ?&gt;
          &lt;/code&gt;
  &lt;?php else: endif ?&gt;
        &lt;/div&gt;      
  &lt;?php $i++; if($i==3) { echo '&lt;div class="clear small_v_margin"&gt;&lt;/div&gt;'; $i=0; } } ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;?php else: ?&gt;
  &lt;p style="font-size:60px;text-align:center;font-family:Arial"&gt;:(&lt;/p&gt;
  &lt;?php
  echo "An error happened. Please send an email to ____ and include which member page you are receiving this error on. Additionally please include the following ID: " . $_GET["id"] . " and " . $headers[0] ; endif
  ?&gt;
  </code></pre>