drisate Posted July 30, 2012 Share Posted July 30, 2012 Hey guys i am trying to use the youtube class created by Sandip Karande. For some reason, it seems like it's not working right ... Warning: SimpleXMLElement::xpath() [simplexmlelement.xpath]: Undefined namespace prefix in /home/mdjlamar/public_html/aCMS/core/ClassYouTubeAPI.php on line 178 You can download the script from here http://www.phpclasses.org/package/6259-PHP-Manage-and-get-information-from-YouTube-videos.html I saw other developers getting this error but did not find any fix to it. I did not touch anything yet apart from the username/password var from the exemple.php file. When i output the result it gets very nasty ... Quote Link to comment Share on other sites More sharing options...
drisate Posted July 30, 2012 Author Share Posted July 30, 2012 Looks like youtube changed it's api and thats the reason why nothing is working in that script As a work arround ... i came up with this: <?php $YouTubeUsername = ""; $feedURL = "https://gdata.youtube.com/feeds/api/users/".$YouTubeUsername."/favorites"; $sxml = simplexml_load_file($feedURL); foreach ($sxml->entry as $entry) { $media = $entry->children('http://search.yahoo.com/mrss/'); $attrs = $media->group->content->attributes(); $videoURL = $attrs['url']; $videoURL = preg_replace('/\?.*/', '', $videoURL); $videoURL = str_replace("/v/","/embed/",$videoURL); $videoTitle = $media->group->title; echo "<div style='float:left;margin:0 15px 15px 0; border: 1px solid black'><iframe frameborder='0' class='youtube-player' width='320' height='245' src='$videoURL'></iframe></div>\n"; } ?> It will list all the favorite videos of a user. I hope this will help others. I am pretty sure you will be able to tweak the code to do what ever oce you get the hang of the new api. good luck! Quote Link to comment Share on other sites More sharing options...
drisate Posted July 31, 2012 Author Share Posted July 31, 2012 Hey guys ;-) just wanted to update this post. I finished the script i wanted to do and now i just wana share it in case somebody else needs something like it ... So what the script does is that it gets a list of all the playlist of a given youtube username then you can click on that playlist to see the videos in them. I used it in combination with prettyPhoto (Jquerry lightbox made by no-margin-for-errors.com) so that explains the need for a thumbnail and the href tag with a rel attribute. $YouTubeUsername = ""; if (!$_GET[playlist]) { $feedURL = "http://gdata.youtube.com/feeds/api/users/".$YouTubeUsername."/playlists?v=2"; $sxml1 = simplexml_load_file($feedURL); foreach ($sxml1->entry as $entry1) { $playlist = explode(":", $entry1->id); echo "<a href='index.php?mod=videos&playlist=".$playlist[5]."'>".$entry1->title."</a><br/>"; } } else { $feedURL = "http://gdata.youtube.com/feeds/api/playlists/".$_GET[playlist]."?v=2"; $sxml = simplexml_load_file($feedURL); foreach ($sxml->entry as $entry) { $media = $entry->children('http://search.yahoo.com/mrss/'); $attrs = $media->group->content->attributes(); $videoURL = $attrs['url']; $videoURL = preg_replace('/\?.*/', '', $videoURL); $videoURL = str_replace("/v/","/embed/",$videoURL); $videoID = explode("/", $videoURL); $videoTitle = $media->group->title; echo "<div style='float:left;margin:0 15px 15px 0; border: 1px solid black'> <a href='http://www.youtube.com/watch?v=$videoID[4]' rel='prettyPhoto' title='$videoTitle' style='display:block;'> <img src='http://img.youtube.com/vi/$videoID[4]/1.jpg' alt='YouTube'/> </a></div>\n"; } } I hope this script will help others. Have fun! And just so you know, i contacted Sandip Karande by skype and his going to update the class he made to work with the last version of the youtube api ... So before you use my script, be sure you take a look at the youtube api class for an update. The code would of been a lot cleaner with it lol Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.