[PHP] YOUTUBE API (REQUEST?)

Dieses Thema im Forum "Webentwicklung" wurde erstellt von Aeonsam, 15. Oktober 2010 .

Schlagworte:
Status des Themas:
Es sind keine weiteren Antworten möglich.
  1. 15. Oktober 2010
    YOUTUBE API (REQUEST?)

    Hallo Leute,

    Will nicht wirklich in das Thema Youtube API´s gehen, habe nur viele Wege gefunden die mich in die Richtung führen.

    Es geht um folgendes:
    Youtube video ID ist klar, mit der kann ich die 2 Sachen einbinden die ich benötige
    1. Video URL (http://www.youtuve.com/v/VID_ID)
    2. VIDEO IMG (http://www.youtuve.com/v/VID_ID/default.jpg)

    Die dritte Sache die ich haben möchte ist der Name (Title) zu dem Clip.

    Ich bin der hoffnung das es sowas einfaches wie:
    http://www.youtube.com/v/VID_ID/reqest_name.php

    LINK gibt der mir dann das ergebniss ausspuckt ^^


    Vieleicht denke ich auch zu einfach aber wenn jemand sowas doch mal gehört / gemacht hat,
    bitte posten.



    VD schon mal im Voraus

    MFG Aeonsam
     
  2. 15. Oktober 2010
    AW: YOUTUBE API (REQUEST?)

    Das sollte dir helfen. Schau mal nach.

    Über die VideoID bekommst du ziemlich viele Sachen raus. Das was du suchst ist


    PHP:
       echo  'Video: '  $videoEntry -> getVideoTitle () .  "\n" ;
    Und die Thumbnails kannst du auch über die funktion dir "catchen"

    PHP:
       $videoThumbnails  $videoEntry -> getVideoThumbnails ();
     
  3. 15. Oktober 2010
    AW: YOUTUBE API (REQUEST?)

    Ja darauf bin ich schon gestoßen. Scheint mir auch die schönste lösung zu sein.
    allerdings möchte ich keine Installation von Zend_Gdata bzw. Framework.php Einbindung
    nur wegen eines Namens vornehmen.
     
  4. 15. Oktober 2010
    AW: YOUTUBE API (REQUEST?)

    dann schau dir doch den quelltext an?

    auf der doku findest du zb. folgenden link:
    http://gdata.youtube.com/feeds/api/videos/ videoID

    wenn du den benutzt bekommst du alle daten die du brauchst in ner xml (atom)

    Spoiler
    HTML:
    <?xml version='1.0' encoding='UTF-8'?>
    <entry 
     xmlns='http://www.w3.org/2005/Atom' 
     xmlns:media='http://search.yahoo.com/mrss/' 
     xmlns:gd='http://schemas.google.com/g/2005' 
     xmlns:yt='http://gdata.youtube.com/schemas/2007'>
     
     <id>http://gdata.youtube.com/feeds/api/videos/the0KZLEacs</id>
     
     <published>2007-06-06T18:02:35.000Z</published>
     
     <updated>2010-08-27T15:15:12.000Z</updated>
     
     <category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
     <category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='News' label='Nachrichten &amp; Politik'/>
     <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='GDD07'/>
     <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='GoogleDeveloperDay'/>
     <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Google'/>
     <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='2007'/>
     
     <title type='text'>Google Developer Day 2007</title>
     
     <content type='text'>Snapshots from Google Developer Day 2007</content>
     
     <link rel='alternate' type='text/html' href='http://www.youtube.com/watch?v=the0KZLEacs&amp;feature=youtube_gdata'/>
     <link rel='http://gdata.youtube.com/schemas/2007#video.responses' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/the0KZLEacs/responses'/>
     <link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/the0KZLEacs/related'/>
     <link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='http://m.youtube.com/details?v=the0KZLEacs'/>
     <link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/the0KZLEacs'/>
     
     <author> 
     <name>GoogleDeveloperDay</name>
     <uri>http://gdata.youtube.com/feeds/api/users/googledeveloperday</uri>
     </author>
     
     <gd:comments>
     <gd:feedLink href='http://gdata.youtube.com/feeds/api/videos/the0KZLEacs/comments' countHint='33'/>
     </gd:comments>
     <media:group>
     <media:category label='Nachrichten &amp; Politik' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>News</media:category>
     
     <media:content 
     url='http://www.youtube.com/v/the0KZLEacs?f=videos&amp;app=youtube_gdata' 
     type='application/x-shockwave-flash' 
     medium='video' 
     isDefault='true' 
     expression='full' 
     duration='169' 
     yt:format='5'/>
     
     <media:content 
     url='rtsp://v2.cache2.c.youtube.com/CiILENy73wIaGQnLacSSKbQXthMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' 
     type='video/3gpp' 
     medium='video' 
     expression='full' 
     duration='169' 
     yt:format='1'/>
     
     <media:content 
     url='rtsp://v3.cache8.c.youtube.com/CiILENy73wIaGQnLacSSKbQXthMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' 
     type='video/3gpp' 
     medium='video' 
     expression='full' 
     duration='169' 
     yt:format='6'/>
     
     <media:description type='plain'>Snapshots from Google Developer Day 2007</media:description>
     <media:keywords>GDD07, GoogleDeveloperDay, Google, 2007</media:keywords>
     <media:player url='http://www.youtube.com/watch?v=the0KZLEacs&amp;feature=youtube_gdata_player'/>
     <media:thumbnail url='http://i.ytimg.com/vi/the0KZLEacs/2.jpg' height='90' width='120' time='00:01:24.500'/>
     <media:thumbnail url='http://i.ytimg.com/vi/the0KZLEacs/1.jpg' height='90' width='120' time='00:00:42.250'/>
     <media:thumbnail url='http://i.ytimg.com/vi/the0KZLEacs/3.jpg' height='90' width='120' time='00:02:06.750'/>
     <media:thumbnail url='http://i.ytimg.com/vi/the0KZLEacs/0.jpg' height='240' width='320' time='00:01:24.500'/>
     <media:title type='plain'>Google Developer Day 2007</media:title><yt:duration seconds='169'/>
     
     </media:group>
     
     <gd:rating average='3.5' max='5' min='1' numRaters='8' rel='http://schemas.google.com/g/2005#overall'/>
     <yt:recorded>2007-05-31</yt:recorded>
     <yt:statistics favoriteCount='21' viewCount='12842'/>
    </entry>

    was will man mehr?!
     
  5. 15. Oktober 2010
    AW: YOUTUBE API (REQUEST?)

    Genau das hab ich gerad auch rausgefunden ^^

    Code:
    <?xml version='1.0' encoding='UTF-8'?>
    <entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007'>
    
    <id>http://gdata.youtube.com/feeds/api/videos/vKUDdQx6QaY</id>
    
    <published>2010-07-09T22:16:13.000Z</published><updated>2010-10-15T17:25:51.000Z</updated>
    <category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Entertainment' label='Unterhaltung'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Contemporary'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='America'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='look'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='at'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='society'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='sped'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='up'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='speed'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='stop'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='motion'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='film'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='video'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='photography'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='dandy'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='noel'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='diana'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='winston'/>
    <category schem='http://gdata.youtube.com/schemas/2007/keywords.cat' term='scott'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='kassenoff'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='ashley'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='trevathan'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='geoffrey'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='yano'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='sound'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='tyler'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='westen'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='makeup'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='krysten'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='grande'/>
    
    
    
    <title type='text'>Contemporary America</title>
    
    
    
    <content type='text'>Contemporary America- we love fast things......
    D14 Productions
    directed by Dandy Noel
    text by Diana Winston
    starring Ashley Trevathan</content><link rel='alternate' type='text/html' href='http://www.youtube.com/watch?v=vKUDdQx6QaY&amp;feature=youtube_gdata'/><link rel='http://gdata.youtube.com/schemas/2007#video.responses' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/vKUDdQx6QaY/responses'/><link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/vKUDdQx6QaY/related'/><link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='http://m.youtube.com/details?v=vKUDdQx6QaY'/><link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/vKUDdQx6QaY'/><author><name>dandynoel</name><uri>http://gdata.youtube.com/feeds/api/users/dandynoel</uri></author><gd:comments><gd:feedLink href='http://gdata.youtube.com/feeds/api/videos/vKUDdQx6QaY/comments' countHint='18'/></gd:comments><media:group><media:category label='Unterhaltung' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Entertainment</media:category><media:content url='http://www.youtube.com/v/vKUDdQx6QaY?f=videos&amp;app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='78' yt:format='5'/><media:content url='rtsp://v3.cache8.c.youtube.com/CiILENy73wIaGQmmQXoMdQOlvBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='78' yt:format='1'/><media:content url='rtsp://v8.cache1.c.youtube.com/CiILENy73wIaGQmmQXoMdQOlvBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='78' yt:format='6'/><media:description type='plain'>Contemporary America- we love fast things......
    D14 Productions
    directed by Dandy Noel
    text by Diana Winston
    starring Ashley Trevathan</media:description>
    <media:keywords>Contemporary, America, look, at, society, sped, up, speed, stop, motion, film, video, photography, dandy, noel, diana, winston, scott, kassenoff, ashley, trevathan, geoffrey, yano, sound, tyler, westen, makeup, krysten, grande</media:keywords>
    <media:player url='http://www.youtube.com/watch?v=vKUDdQx6QaY&amp;feature=youtube_gdata_player'/>
    <media:thumbnail url='http://i.ytimg.com/vi/vKUDdQx6QaY/2.jpg' height='90' width='120' time='00:00:39'/>
    <media:thumbnail url='http://i.ytimg.com/vi/vKUDdQx6QaY/1.jpg' height='90' width='120' time='00:00:19.500'/>
    <media:thumbnail url='http://i.ytimg.com/vi/vKUDdQx6QaY/3.jpg' height='90' width='120' time='00:00:58.500'/>
    <media:thumbnail url='http://i.ytimg.com/vi/vKUDdQx6QaY/0.jpg' height='240' width='320' time='00:00:39'/>
    <media:title type='plain'>Contemporary America</media:title><yt:duration seconds='78'/>
    </media:group><gd:rating average='3.6666667' max='5' min='1' numRaters='105' rel='http://schemas.google.com/g/2005#overall'/><yt:statistics favoriteCount='34' viewCount='13200'/>
    </entry>
    



    jetzt brauch nur noch den tipp wie ich in dex XML den <title> ansprechen kann...


    MFG Aeonsam
     
  6. 15. Oktober 2010
    AW: YOUTUBE API (REQUEST?)

    Über einen XML Parser?

    [G]php xml parser[/G]
     
  7. 15. Oktober 2010
    AW: YOUTUBE API (REQUEST?)

    War auch nur das Beispiel. Wie Murdoc schon gesagt hatte, der Link erfüllt den gleichen Zweck.



    Zu der XML Datei.

    function.simplexml-load-file

    Damit die Datei einlesen und dann als Beispiel:


    PHP:
    <? php


    $xml 
    simplexml_load_file ( 'xml.xml' );


    //Zugriff auf die ID $xml->id
    echo  $xml -> id ;

    //Zugriff auf Array 0 von category
    print_r ( $xml -> category [ 0 ]);

    //1
    print_r ( $xml -> category [ 1 ]);

    //ect.


    //Zugriff auf category Array

    $cat = $xml -> category [ 6 ];

    echo 
    $cat -> attributes ()-> scheme ;
    ?>
     
  8. 15. Oktober 2010
    AW: YOUTUBE API (REQUEST?)

    Thx hat super geklappt!!!!

    Danke euch für die schnellen Antworten.
    Und schön ohne Zend Framework.
    BW ist raus..
     
  9. 16. Oktober 2010
    AW: YOUTUBE API (REQUEST?)

    Ne Frage hab ich doch noch.

    den title krieg ich ja so:

    echo $xml->title;


    jetzt werd ich doch gierig und möchte die viewCount='13200' mir mit ausgeben lasssen.

    HTML:
    <gd:rating average='3.6666667' max='5' min='1' numRaters='105' rel='http://schemas.google.com/g/2005#overall'/><yt:statistics favoriteCount='34' viewCount='13200'/>
    

    MFG Aeonsam
     
  10. 16. Oktober 2010
    AW: YOUTUBE API (REQUEST?)

    PHP:

    $result 
    $xml -> xpath ( '//yt:statistics' ); 
      
    echo 
    $result [ 0 ]-> attributes ()-> viewCount ;

    Bitteschön ^^
     
  11. 17. Oktober 2010
    AW: YOUTUBE API (REQUEST?)

    Dake vielmals
     
  12. 24. Oktober 2010
    AW: YOUTUBE API (REQUEST?)

    Hi Leute,

    hab wieder was


    es geht darum wenn das yt video gelöscht wird möchte ich den warning error gern abfangen. (failed to open stream) ich dachte da an

    if(file_exists())


    leider habe ich in den url pfad keine endung zur Datei.

    Bsp:
    http://gdata.youtube.com/feeds/api/videos/AkpmqOWfvUo // geht da das video vorhanden ist

    http://gdata.youtube.com/feeds/api/videos/kwqxVHqhxoo // geht nicht da das video del ist


    mein prob ist aber das beim if(file_exists()) egal ob ich ein ex - oder nicht-exestierendes video nehme den else (also file dont exist) bekomme.

    Code:
    <?php
    $filename = 'http://gdata.youtube.com/feeds/api/videos/AkpmqOWfvUo';
    if (file_exists($filename)) {
     print "The file $filename exists";
    } else {
     print "The file $filename does not exist";
    }
    ?>
    
     
  13. 24. Oktober 2010
    AW: YOUTUBE API (REQUEST?)

    failed to open stream? was zu hölle machst du denn da?
    bei deinem link steht dann "Private Video" -> die datei existiert also.
     
  14. 24. Oktober 2010
    AW: YOUTUBE API (REQUEST?)

    ich mache dort folgendes

    Code:
    
    <?
     $vid_load_xml = "http://gdata.youtube.com/feeds/api/videos/kwqxVHqhxoo";
     $vid_xml = simplexml_load_file($vid_load_xml);
     $vid_title = $vid_xml->title;
     $vid_content = $vid_xml->content;
    ?>
    
    
    ausgabe:





    Warning: simplexml_load_file(http://gdata.youtube.com/feeds/api/videos/kwqxVHqhxoo) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in C:\xampp\htdocs\www\TestArea\XML\useberpruefung_ob_file_exestiert.php on line 9

    Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://gdata.youtube.com/feeds/api/videos/kwqxVHqhxoo" in C:\xampp\htdocs\www\TestArea\XML\useberpruefung_ob_file_exestiert.php on line 9
     
  15. 24. Oktober 2010
    AW: YOUTUBE API (REQUEST?)

    hier eine funktion mit der du testen kannst ob die seite existiert:

    PHP:
    <? php

    function  http_resource_available ( $url $rec  false )
    {
        
    $host  parse_url ( $url PHP_URL_HOST );
        
    $path  parse_url ( $url PHP_URL_PATH );
        
    $path  = empty( $path ) ?  '/'  $path ;
        
        if((
    $query  parse_url ( $url PHP_URL_QUERY )) !=  '' )
            
    $path  .=  '?'  $query ;
        
        
    $errstr  $errno  '' ;
        
    $socket  fsockopen ( $host 80 $errstr $errno 30 );
        
        if(!
    $socket ) return  false ;
        
        
    $header  sprintf ( "HEAD %s HTTP/1.1\r\nHost: %s\r\n" $path $host );
        
    $header  .=  "User-Agent: Mozilla/5 (Independent) Gecko/20101012 Firefox/3.6.11\r\n" ;
        
    $header  .=  "Connection: close:\r\n\r\n" ;
        
        
    fwrite ( $socket $header );
        
    $data  fread ( $socket 1024 );
        
    fclose ( $socket );
        
        
    $match  = array();
        
    preg_match ( '/^HTTP\/[\d\.]+ (\d{3})/i' $data $match );
        
        if(empty(
    $match [ 1 ]))
            return 
    false ;
        
        
    $status  = (int)  $match [ 1 ];
        unset(
    $match );
        
        if(
    $status  >=  200  &&  $status  <=  207 )
            return 
    true ;
            
        if(
    $status  302  ||  $rec  ===  false )
            return 
    false ;
            
        
    $match  = array();
        
    preg_match ( '/Location:(.*)$/m' $data $match );
        
        if(empty(
    $match [ 1 ]))
            return 
    false ;
        
        
    $location  trim ( $match [ 1 ]);
        unset(
    $match );
        
        return 
    http_resource_available ( $location );  
    }
    beispiel:
    PHP:
    $url  'http://gdata.youtube.com/feeds/api/videos/kwqxVHqhxoo' ;
    if(!
    http_resource_available ( $url ))
        exit(
    'seite existiert nicht' );

    // weitermachen    
    $vid_xml  simplexml_load_file ( $vid_load_xml );
    $vid_title  $vid_xml -> title ;
    $vid_content  $vid_xml -> content ;
     
  16. 24. Oktober 2010
    AW: YOUTUBE API (REQUEST?)

    Perfekt danke
     
  17. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.