PHP将代码api 2嵌入到Api3中

时间:2015-04-22 05:05:10

标签: php youtube-api

我有这个脚本创建了一个php文件,我在我的网页上使用它来显示dailey视频。

<?PHP  // Mar 3, 2012

// the Zend dir must be in your include_path
set_include_path('/usr/lib64/php/include/ZendGdata-1.12.3/library');
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');

$user = 'dingo001';
echo "Get last video for " . $user . "...\n";
$feed = GetLastVideoByUser($user);
if ($feed)
  {
    foreach($feed as $entry)
       {
         $videoId = $entry->getVideoId();
         echo "Create embedded object script for video " . $videoId .
"...\n";
         FileVideoId($videoId);
         break;  // 1 file only
       }

  }

echo "Done!\n";
RETURN;
//  --- end of main ---

function GetLastVideoByUser($user, $maxResults=1)
{ // get last uploaded video from user
  // copied from other application and modified:
  // getTopRatedVideosByUser($user, $maxResults=10, $orderBy='rating', $vidFormat=5)

    $userVideosUrl = 'http://gdata.youtube.com/feeds/users/' .
                   $user . '/uploads';
    $youTubeService = new Zend_Gdata_YouTube();
    $ytQuery = $youTubeService->newVideoQuery($userVideosUrl);
    // retrieve a maximum of videos
    $ytQuery->setMaxResults($maxResults);
    try { $feed = $youTubeService->getVideoFeed($ytQuery); }
    catch (Zend_Gdata_App_HttpException $httpException)
          { echo $httpException->getRawResponseBody();}
    catch (Zend_Gdata_App_Exception $e)
          {  echo $e->getMessage();}
 RETURN ($feed);
} // end of function

function FileVideoId($videoId, $filename="youtube-object.php")
{ // Write $somecontent to our file.

 if (!$handle = fopen($filename, 'w'))
  {
   echo "Cannot open file ($filename)";
   RETURN;
  }
$somecontent = '<center><object width="640" height="505">'
              . '<param name="movie" value="http://www.youtube.com/v/'
              . $videoId
              . '&hl=en_GB&fs=1&color1=0x2b405b&color2=0x6b8ab6"></
param>'
              . '<param name="allowFullScreen" value="true"></param>'
              . '<param name="allowscriptaccess" value="always"></
param>'
              . '<embed src="http://www.youtube.com/v/'
              . $videoId
              . '&hl=en_GB&fs=1&color1=0x2b405b&color2=0x6b8ab6"'
              . ' type="application/x-shockwave-flash"'
              . ' allowscriptaccess="always"'
              . ' allowfullscreen="true"'
              . ' width="640" height="505">'
              . '</embed></object></center>';

if (fwrite($handle, $somecontent) === FALSE)
 {
   echo "Cannot write to file ($filename)";
   RETURN;
 }
 fclose($handle);
} // end of function
?>

它会创建一个如下所示的文件:

[code]
<center><object width="640" height="505"><param name="movie" value="http://www.youtube.com/v/UKY3scPIMd8&hl=en_GB&fs=1&color1=0x2b405b&color2=0x6b8ab6"></
param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></
param><embed src="http://www.youtube.com/v/UKY3scPIMd8&hl=en_GB&fs=1&color1=0x2b405b&color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object></center>
[/code]

今天版本3已启动,并且创建的文件不再有效,并且该网页会获取youtube设备不支持的视频。

[url] http://dingo-den.com/index.php?nav=timelapse [/ url]

我不是程序员,所以想帮助PHP代码创建一个文件,在我的veb页面上显示视频。

干杯,

野狗

0 个答案:

没有答案