Fout bij zoeken in script ?

Status
Niet open voor verdere reacties.

tombalfoort

Gebruiker
Lid geworden
25 sep 2006
Berichten
386
Hallo allemaal ik heb een script gevonden en ik zit met het volgende probleem:

Als je wat gaat zoeken en er een space ( ) tussen zet, dan geeft hij de volgende error aan::

Warning: file_get_contents(http://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag&dev_id=ARgbYoNTCbs&tag=rise up&page=1&per_page=19) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 500 Server Error in /home/ftp/webmaster@media****.com/html/youtube/youtube.class.php on line 171

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/ftp/webmaster@media****.com/html/youtube/youtube.class.php:172 Stack trace: #0 /home/ftp/webmaster@media****.com/html/youtube/youtube.class.php(172): SimpleXMLElement->__construct('') #1 /home/ftp/webmaster@media****.com/html/youtube/youtube.class.php(138): youtube->display() #2 /home/ftp/webmaster@media****.com/html/youtube/index.php(10): youtube->videos('BlackEyedPeas') #3 {main} thrown in /home/ftp/webmaster@media****.com/html/youtube/youtube.class.php on line 172



Ik heb al gekeken wat er is, maar ik wordt niet wijs van de foutmelding.

Wie kan mij hierbij helpen ?

(ik heb de bestanden in een zip file bijgevoegt.)

groetjes Tom
 

Bijlagen

Komt het niet toevallig omdat YouTube er uit ligt? Ik kan er in ieder geval niet naar surfen...
 
Youtube kan inderdaag traag zijn of wordt gewoon niet geopend.

Maar ik zit alleen met het probleem dat als je rechts boven in het zoekvak meer dan 1 woord er in zet dat hij een error aangeeft.

Hij maakt niet zelf door een of andere manier zelf van een space een + zodat youtube weet.

Okj, nu moet ik ook naar dat wordt zoeken. En dat gebeurt niet want youtube snapt niet wat hij moet verzenden.

Ik weet niet of het nu duidelijk is. Want verder werkt alles gewoon goed...
 
Laatst bewerkt:
Kwestie van de functie str_replace(); gebruiken ;)
PHP:
$zoek = "helpmij is de beste site";
$zoekterm = str_replace(" ", "+", $zoek);
echo $zoekterm;
 
Bedankt voor je reactsie, maar ik snap het niet helemaal.

Ik weet niet waar ik het bij zou moeten zetten

Groetjes Tom

P.S. Dit zijn de twee pagina's die ik in die map gebruik

Ik kan de link hier niet zetten ivm het woordenfiltersysteem.

Index.php

PHP:
<?php
	// include the youtube class and instantiate it with the object $yt
	include('youtube.class.php');
	$yt = new youtube();
	
	// set the amount of results per page, in this case, 19
	$yt->set('per_page', 20);
	
	// get videos by a tag (default search string is "mutemath" in this case ,you can change it to whatever you want.
	$res = $yt->videos('aquarijn');
	
	// build the video list array
	$video_list = $res['video_list']['video'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head> <script language="Javascript">if (top.location != self.location) {
top.location = self.location.href
}</script><LINK rel="SHORTCUT ICON" href="http://www.media****.com/fv005.ico">
	<title>Media****.com = YouTube</title>
	<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="frame">
	<div id="contentheader">
		<form method="get">
			<h1><a href='http://www.media****.com/youtube/'>Media****.com = YouTube</a></h1>
			<input type="text" name="tag">
			<input type="submit" value="Zoeken">
		</form>
	</div>
	<div id="contentleft">
		<div class="paginate"> <a href="?page=<?=YOUTUBE_PREV_PAGE ?>"><< Vorige</a> :: page <?=YOUTUBE_PAGE ?> of <?=YOUTUBE_TOTAL_PAGES ?> :: <a href="?page=<?=YOUTUBE_NEXT_PAGE ?>">Volgende >></a></div>
		<center><BR><script type="text/javascript"><!--
google_ad_client = "pub-7899080074660706";
google_ad_width = 234;
google_ad_height = 60;
google_ad_format = "234x60_as";
google_ad_type = "text_image";
google_ad_channel = "";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><BR><BR></center><table>
			<tr>
				<?php
				// loop through each video in the list and display it for design purposes
					$i = 0;
					foreach ($video_list as $k => $v) {
						// limit the title's length so it doesn't break the design
						$title = substr($v['title'], 0, 15) . '...';
						echo "<td class='thumb'>
							<a href='?video_id={$v['id']}'><img src='{$v['thumbnail_url']}'></a><br />
							<span class='title_short'>{$title}</span><br />
							<span class='length_short'>{$v['length_seconds']}</span>
							<span class='rating_short'>{$v['rating_avg']} / {$v['rating_count']}</span>
						</td>";
						$i++;
						// only 3 videos per row
						if ($i == 3) {
							$i = 0;
							echo '</tr><tr>';
						}
					}
				?>
			</tr>
		</table><center><BR><script type="text/javascript"><!--
google_ad_client = "pub-7899080074660706";
google_ad_width = 234;
google_ad_height = 60;
google_ad_format = "234x60_as";
google_ad_type = "text_image";
google_ad_channel = "";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center<BR>
		<div class="paginate"> <a href="?page=<?=YOUTUBE_PREV_PAGE ?>"><< Vorige</a> :: page <?=YOUTUBE_PAGE ?> of <?=YOUTUBE_TOTAL_PAGES ?> :: <a href="?page=<?=YOUTUBE_NEXT_PAGE ?>">Volgende >></a></div>
	</div>
	<div id="contentcenter">
		<h2><?=$video_list[YOUTUBE_VIDEO_INDEX]['title'] ?></h2>
		<object width="425" height="350">
			<param name="movie" value="http://www.youtube.com/v/<?=YOUTUBE_VIDEO_ID ?>&autoplay=1&rel=0"></param>
			<param name="wmode" value="transparent"></param>
			<embed src="http://www.youtube.com/v/<?=YOUTUBE_VIDEO_ID ?>" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed>
		</object>
		<div id="description">
			<?=$video_list[YOUTUBE_VIDEO_INDEX]['description'] ?>
		</div>
		<div class="stats">Aantal Views: <span class="statVal"><?=$video_list[YOUTUBE_VIDEO_INDEX]['view_count'] ?></span><br />
			Reacties: <span class="statVal"><?=$video_list[YOUTUBE_VIDEO_INDEX]['comment_count'] ?></span><br />
			Tags: <span class="statVal"><?=$yt->tags_for_video($video_list[YOUTUBE_VIDEO_INDEX]['tags']) ?></span><br />
		
<BR><center><script type="text/javascript"><!--
google_ad_client = "pub-7899080074660706";
google_ad_width = 250;
google_ad_height = 250;
google_ad_format = "250x250_as";
google_ad_type = "image";
google_ad_channel = "";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center>

</div>
	</div>
	<br clear="all" />
	<div id="contentfooter">Media****.com</div>
</div>
</body><script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2845423-1";
urchinTracker();
</script>
</html>

youtube.class.php

PHP:
<?php
error_reporting(E_ALL);

// for pagination
session_start();

define('API_URL', 'http://www.youtube.com/');

// CALL GATEWAYS
define('API_REST_CALL', API_URL . 'api2_rest?');
define('API_XMLRPC_CALL', API_URL . 'api2_xmlrpc?');
 
// METHODS FOR VIDEOS
define('BY_TAG', 'list_by_tag');

// create youtube class
class youtube {
	// CLASS PROPERTIES
	public
	// VARIABLE TO HOLD THE SIMPLE XML ELEMENT WITH RETURNED DATA
	$xml,
	// HOLDS CONFIG OPTIONS
	$config = array(),
	// VAR TO STORE THE QUERY STRING FOR YOUTUBE
	$api_call,
	// RETURNED DATA FROM XML CALL
	$return,
	$tag,
	// IF WE ENCOUNTER ERRORS ALONG OUR JOURNEY
	$errors;

	// CONSTRUCTION VARIABLES
	public function __construct($api_key = API_KEY, $page = 1, $per_page = 25) {
		// JUST TO SETUP SOME DEFAULT VALUES FOR A NOMINAL CALL.
		// WE WANTED TO MAKE IT EASY TO JUST USE THE CLASS, NOT CONFIGURE IT.
		youtube::set('api_key', API_KEY);
		youtube::set('page', $page);
		youtube::set('per_page', $per_page);

		// modify the call
		youtube::modify_call(API_REST_CALL . 'method=youtube.');
	}

	function xml_to_array($xml) {
		$fils = 0;
		$tab = false;
		$array = array();

		foreach($xml->children() as $key => $value) {
			$child = youtube::xml_to_array($value);

			//To deal with the attributes
			//foreach ($node->attributes() as $ak => $av) {
			//	$child[$ak] = (string)$av;
			//}
			//Let see if the new child is not in the array
			if ($tab == false && in_array($key, array_keys($array))) {
				//If this element is already in the array we will create an indexed array
				$tmp = $array[$key];
				$array[$key] = NULL;
				$array[$key][] = $tmp;
				$array[$key][] = $child;
				$tab = true;
			} elseif($tab == true) {
				//Add an element in an existing array
				$array[$key][] = $child;
			} else {
				//Add a simple element
				$array[$key] = $child;
			}
			$fils++;
		}

		if($fils==0) {
			return (string)$xml;
		}
		return $array;
	}

	// SET A CONFIG VARIABLE
	public function set($item, $value) {
		$this->config[$item] = $value;
	}

	// ACCESS CONFIG
	public function config($item) {
		return $this->config[$item];
	}

	// MODIFY THE CALL CLASS PROPERTY
	public function modify_call($params) {
		$this->api_call .= $params;
	}

	// ECHO THE CALL FOR DEBUGGING
	public function return_call() {
		return $this->api_call;
	}

	// YOUTUBE VIDEO METHODS
	public function videos($data = 'mutemath', $method = BY_TAG) {
		//---------------------------------------------//
		$this->api_call .= 'videos.'; ///////////////////////
		//---------------------------------------------//
		switch ($method) {
			case BY_TAG:
				if (isset($_GET['tag'])) {
					$this->tag = '&tag=' . $_GET['tag'];
				} else {
					$this->tag = '&tag='. $data;
				}
				youtube::modify_call($method . '&dev_id=' . $this->config['api_key'] . $this->tag);
				break;

			default:
				return 'The WaxJelly YouTube API Class only supports retrieving videos by tag.';
				break;
		}

		// CALL DISPLAY
		return youtube::display();
	}

	public function tags_for_video($tags) {
		$tag_links = '';

		// explode
		$x = explode(' ', $tags);
		if (count($x) > 0) {
			foreach ($x as $k => $v) {
				$tag_links .= "<a href=\"{$_SERVER['PHP_SELF']}?tag=$v\">$v</a> ";
			}
		} else { 
			$tag_links = "<a href=\"{$_SERVER['PHP_SELF']}?tag=mutemath\">mutemath</a>";
		}
		return $tag_links;
	}

	// DISPLAY RESULTS
	public function display() {
		// CHECK FOR A NEW PAGE & PER PAGE
		if (isset($_GET['page'])) {
			youtube::set('page', $_GET['page']);
		}
		if (isset($_GET['per_page'])) {
			youtube::set('per_page', $_GET['per_page']);
		}

		// per page, page, prev, next
		// total videos, total pages
		youtube::modify_call('&page=' . youtube::config('page') . '&per_page=' . youtube::config('per_page'));

		// SEND REQUEST
		$this->return = file_get_contents(youtube::return_call());
		$this->xml = new SimpleXMLElement($this->return);
		$this->xml = youtube::xml_to_array($this->xml);

		// CHECK IF THEY'RE ASKING FOR A VIDEO ID
		if (isset($_GET['video_id'])) {
			define('YOUTUBE_VIDEO_ID', $_GET['video_id']);
			
			// loop through videos to get videos index
			foreach ($this->xml['video_list']['video'] as $indx => $array) {
				if ($array['id'] == $_GET['video_id']) {
					$index = $indx;
					echo $index;
					break;
				} else {
					$index = '';
				}
			}

			// define index
			define('YOUTUBE_VIDEO_INDEX', $index);
		} else {
			define('YOUTUBE_VIDEO_ID', $this->xml['video_list']['video'][0]['id']);
			define('YOUTUBE_VIDEO_INDEX', 0);
		}

		//////////////////////////////////////////
		// CREATE DISPLAY CONSTANTS //
		/////////////////////////////////////////
		define('YOUTUBE_PAGE', youtube::config('page'));
		define('YOUTUBE_PER_PAGE', youtube::config('per_page'));
		$prev = (youtube::config('page') - 1 == 0) ? 1 : youtube::config('page') - 1;
		define('YOUTUBE_PREV_PAGE', $prev . $this->tag);
		define('YOUTUBE_NEXT_PAGE', youtube::config('page') + 1 . $this->tag);
		define('YOUTUBE_TOTAL_VIDEOS', $this->xml['video_list']['total']);
		define('YOUTUBE_TOTAL_PAGES', ceil($this->xml['video_list']['total'] / youtube::config('per_page')));

		// CONVERT FROM SIMPLEXML OBJECT TO ARRAY
		return $this->xml;
	}
}
?>
 
Waarschijnlijk moet je het in de functie videos zetten.
PHP:
public function videos($data = 'mutemath', $method = BY_TAG) { 
  //---------------------------------------------// 
  $this->api_call .= 'videos.'; /////////////////////// 
  //---------------------------------------------// 
  switch ($method) { 
    case BY_TAG: 
      if (isset($_GET['tag'])) {
        //Creating the right format
        $keyword = str_replace(" ", "+", $_GET['tag']);
        //Returning the adjusted URL 
        $this->tag = '&tag=' . $keyword; 
      } else { 
        $this->tag = '&tag='. $data; 
      } 
      youtube::modify_call($method . '&dev_id=' . $this->config['api_key'] . $this->tag); 
    break;
    default: 
      return 'The WaxJelly YouTube API Class only supports retrieving videos by tag.'; 
    break; 
  } 
  // CALL DISPLAY 
  return youtube::display(); 
}
 
hey bedankt :thumb: ik heb hem erin gezet en ik krijg nu (dat ik heel vervelend vindt omdat ik klaar hoopte te zijn) weer een foutmelding met de volgende functie (geloof ik)


Parse error: syntax error, unexpected T_PUBLIC in /home/ftp/webmaster@media****.com/html/youtube/youtube.class.php on line 143
 
Heb je hem er zelf in gezet of heb je het gedeelte van mij overgenomen? (Hierboven dus)
 
ik heb de code die hierboven overgenomen...

want zelf wist ik niet waar ik het er in moest zetten.
 
Waarschijnlijk heb je iets te veel verwijderd.
Dit is de volledige class:
PHP:
<?php 
error_reporting(E_ALL); 

// for pagination 
session_start(); 

define('API_URL', 'http://www.youtube.com/'); 

// CALL GATEWAYS 
define('API_REST_CALL', API_URL . 'api2_rest?'); 
define('API_XMLRPC_CALL', API_URL . 'api2_xmlrpc?'); 

// METHODS FOR VIDEOS 
define('BY_TAG', 'list_by_tag'); 

// create youtube class 
class youtube { 
  // CLASS PROPERTIES 
  public 
  // VARIABLE TO HOLD THE SIMPLE XML ELEMENT WITH RETURNED DATA 
  $xml, 
  // HOLDS CONFIG OPTIONS 
  $config = array(), 
  // VAR TO STORE THE QUERY STRING FOR YOUTUBE 
  $api_call, 
  // RETURNED DATA FROM XML CALL 
  $return, 
  $tag, 
  // IF WE ENCOUNTER ERRORS ALONG OUR JOURNEY 
  $errors; 

  // CONSTRUCTION VARIABLES 
  public function __construct($api_key = API_KEY, $page = 1, $per_page = 25) { 
    // JUST TO SETUP SOME DEFAULT VALUES FOR A NOMINAL CALL. 
    // WE WANTED TO MAKE IT EASY TO JUST USE THE CLASS, NOT CONFIGURE IT. 
    youtube::set('api_key', API_KEY); 
    youtube::set('page', $page); 
    youtube::set('per_page', $per_page); 
    // modify the call 
    youtube::modify_call(API_REST_CALL . 'method=youtube.'); 
  }
   
  function xml_to_array($xml) { 
    $fils = 0; 
    $tab = false; 
    $array = array(); 
    
    foreach($xml->children() as $key => $value) { 
      $child = youtube::xml_to_array($value); 

      //To deal with the attributes 
      //foreach ($node->attributes() as $ak => $av) { 
      //    $child[$ak] = (string)$av; 
      //} 
      //Let see if the new child is not in the array 
      if ($tab == false && in_array($key, array_keys($array))) { 
        //If this element is already in the array we will create an indexed array 
        $tmp = $array[$key]; 
        $array[$key] = NULL; 
        $array[$key][] = $tmp; 
        $array[$key][] = $child; 
        $tab = true; 
      } elseif($tab == true) { 
        //Add an element in an existing array 
        $array[$key][] = $child; 
      } else { 
        //Add a simple element 
        $array[$key] = $child; 
      } 
      $fils++; 
    } 
    if($fils==0) { 
      return (string)$xml; 
    } 
    return $array; 
  } 
  // SET A CONFIG VARIABLE 
  public function set($item, $value) { 
    $this->config[$item] = $value; 
  } 
  // ACCESS CONFIG 
  public function config($item) { 
    return $this->config[$item]; 
  } 
  // MODIFY THE CALL CLASS PROPERTY 
  public function modify_call($params) { 
    $this->api_call .= $params; 
  } 
  // ECHO THE CALL FOR DEBUGGING 
  public function return_call() { 
    return $this->api_call; 
  } 
  // YOUTUBE VIDEO METHODS 
  public function videos($data = 'mutemath', $method = BY_TAG) { 
    //---------------------------------------------// 
    $this->api_call .= 'videos.'; /////////////////////// 
    //---------------------------------------------// 
    switch ($method) { 
      case BY_TAG: 
        if (isset($_GET['tag'])) { 
          //Creating the right format 
          $keyword = str_replace(" ", "+", $_GET['tag']); 
          //Returning the adjusted URL 
          $this->tag = '&tag=' . $keyword; 
        } else { 
          $this->tag = '&tag='. $data; 
        } 
        youtube::modify_call($method . '&dev_id=' . $this->config['api_key'] . $this->tag); 
      break; 
      default: 
        return 'The WaxJelly YouTube API Class only supports retrieving videos by tag.'; 
      break; 
    } 
    // CALL DISPLAY 
    return youtube::display(); 
  } 

  public function tags_for_video($tags) { 
    $tag_links = ''; 
    // explode 
    $x = explode(' ', $tags); 
    if (count($x) > 0) { 
      foreach ($x as $k => $v) { 
        $tag_links .= "<a href=\"{$_SERVER['PHP_SELF']}?tag=$v\">$v</a> "; 
      } 
    } else { 
      $tag_links = "<a href=\"{$_SERVER['PHP_SELF']}?tag=mutemath\">mutemath</a>"; 
    } 
    return $tag_links; 
  } 

  // DISPLAY RESULTS 
  public function display() { 
    // CHECK FOR A NEW PAGE & PER PAGE 
    if (isset($_GET['page'])) { 
      youtube::set('page', $_GET['page']); 
    } 
    if (isset($_GET['per_page'])) { 
      youtube::set('per_page', $_GET['per_page']); 
    } 

    // per page, page, prev, next 
    // total videos, total pages 
    youtube::modify_call('&page=' . youtube::config('page') . '&per_page=' . youtube::config('per_page')); 
    // SEND REQUEST 
    $this->return = file_get_contents(youtube::return_call()); 
    $this->xml = new SimpleXMLElement($this->return); 
    $this->xml = youtube::xml_to_array($this->xml); 
    // CHECK IF THEY'RE ASKING FOR A VIDEO ID 
    if (isset($_GET['video_id'])) { 
      define('YOUTUBE_VIDEO_ID', $_GET['video_id']); 
      // loop through videos to get videos index 
      foreach ($this->xml['video_list']['video'] as $indx => $array) { 
        if ($array['id'] == $_GET['video_id']) { 
          $index = $indx; 
          echo $index; 
          break; 
        } else { 
          $index = ''; 
        } 
      } 
      // define index 
      define('YOUTUBE_VIDEO_INDEX', $index); 
    } else { 
      define('YOUTUBE_VIDEO_ID', $this->xml['video_list']['video'][0]['id']); 
      define('YOUTUBE_VIDEO_INDEX', 0); 
    } 
    ////////////////////////////////////////// 
    // CREATE DISPLAY CONSTANTS // 
    ///////////////////////////////////////// 
    define('YOUTUBE_PAGE', youtube::config('page')); 
    define('YOUTUBE_PER_PAGE', youtube::config('per_page')); 
    $prev = (youtube::config('page') - 1 == 0) ? 1 : youtube::config('page') - 1; 
    define('YOUTUBE_PREV_PAGE', $prev . $this->tag); 
    define('YOUTUBE_NEXT_PAGE', youtube::config('page') + 1 . $this->tag); 
    define('YOUTUBE_TOTAL_VIDEOS', $this->xml['video_list']['total']); 
    define('YOUTUBE_TOTAL_PAGES', ceil($this->xml['video_list']['total'] / youtube::config('per_page'))); 

    // CONVERT FROM SIMPLEXML OBJECT TO ARRAY 
    return $this->xml; 
  } 
} 
?>
Ik heb deze even getest en ik krijg bij de url netjes een + in plaats van de spatie.
 
Hij doet het nu inderdaag beter. Hij laat nu gewoon de pagina zien, maar hij zegt nu dat hij de api key niet kan vinden en de videolijst

De foutmeldingen :S

Notice: Use of undefined constant API_KEY - assumed 'API_KEY' in /home/ftp/webmaster@media****.com/html/youtube/youtube.class.php on line 33

Notice: Use of undefined constant API_KEY - assumed 'API_KEY' in /home/ftp/webmaster@media****.com/html/youtube/youtube.class.php on line 36

Notice: Undefined index: video_list in /home/ftp/webmaster@media****.com/html/youtube/youtube.class.php on line 165

Notice: Undefined index: video_list in /home/ftp/webmaster@media****.com/html/youtube/youtube.class.php on line 176

Notice: Undefined index: video_list in /home/ftp/webmaster@media****.com/html/youtube/youtube.class.php on line 177

Notice: Undefined index: video_list in /home/ftp/webmaster@media****.com/html/youtube/index.php on line 13


en deze op de plek waar de video's staan...

Warning: Invalid argument supplied for foreach() in /home/ftp/webmaster@media****.com/html/youtube/index.php on line 50
 
Je hoort in index.php bij het aanmaken van de klasse een API sleutel meegeven, die sleutel hoor je bij YouTube te kunnen verkrijgen.

Dit staat er op de site van de maker:
Let’s get started. First, let’s talk about what you’ll need in order to implement this class.

- A YouTube API Developer’s Key
- A server running PHP5
- 20 minutes or so
Dat geeft dus die errors
Notice: Use of undefined constant API_KEY - assumed 'API_KEY' in /home/ftp/webmaster@media****.com/html/youtube/youtube.class.php on line 33

Notice: Use of undefined constant API_KEY - assumed 'API_KEY' in /home/ftp/webmaster@media****.com/html/youtube/youtube.class.php on line 36

Ik stel voor dat je de huidige versie gebruikt, ik heb het str_replace gedeelte er in verwerkt. Kijk maar of deze minder errors geeft
youtube.class.php
PHP:
<?php
error_reporting(E_ALL);

// for pagination
session_start();

////////////////////////////////////////
// youtube.class.php v1.0 /////////
// released 3/8/2007 ///////////////
// for waxjelly.wordpress.com ////
// the internet is for users ////////
////////////////////////////////////////
// this class is to be used free ////
// of charge so long as this line //
// remains intact, and untouched/
////////////////////////////////////////
define('API_KEY', 'ARgbYoNTCbs'); // YOUR YOUTUBE DEVELOPERS API KEY
//-------------------------------//
// DO NOT EDIT
//-------------------------------//
/////////////////////
// CONSTANTS //
////////////////////
define('API_URL', 'http://www.youtube.com/');

// CALL GATEWAYS
define('API_REST_CALL', API_URL . 'api2_rest?');
define('API_XMLRPC_CALL', API_URL . 'api2_xmlrpc?');
 
// METHODS FOR VIDEOS
define('BY_TAG', 'list_by_tag');

// create youtube class
class youtube {
  // CLASS PROPERTIES
  public
  // VARIABLE TO HOLD THE SIMPLE XML ELEMENT WITH RETURNED DATA
  $xml,
  // HOLDS CONFIG OPTIONS
  $config = array(),
  // VAR TO STORE THE QUERY STRING FOR YOUTUBE
  $api_call,
  // RETURNED DATA FROM XML CALL
  $return,
  $tag,
  // IF WE ENCOUNTER ERRORS ALONG OUR JOURNEY
  $errors;
  // CONSTRUCTION VARIABLES
  public function __construct($api_key = API_KEY, $page = 1, $per_page = 25) {
    // JUST TO SETUP SOME DEFAULT VALUES FOR A NOMINAL CALL.
    // WE WANTED TO MAKE IT EASY TO JUST USE THE CLASS, NOT CONFIGURE IT.
    youtube::set('api_key', API_KEY);
    youtube::set('page', $page);
    youtube::set('per_page', $per_page);
    // modify the call
    youtube::modify_call(API_REST_CALL . 'method=youtube.');
  }
  function xml_to_array($xml) {
    $fils = 0;
    $tab = false;
    $array = array();
    foreach($xml->children() as $key => $value) {
      $child = youtube::xml_to_array($value);
      //To deal with the attributes
      //foreach ($node->attributes() as $ak => $av) {
      //$child[$ak] = (string)$av;
      //}
      //Let see if the new child is not in the array
      if ($tab == false && in_array($key, array_keys($array))) {
        //If this element is already in the array we will create an indexed array
        $tmp = $array[$key];
        $array[$key] = NULL;
        $array[$key][] = $tmp;
        $array[$key][] = $child;
        $tab = true;
      } elseif($tab == true) {
        //Add an element in an existing array
        $array[$key][] = $child;
      } else {
        //Add a simple element
        $array[$key] = $child;
      }
      $fils++;
    }
    if($fils==0) {
      return (string)$xml;
    }
    return $array;
  }
  // SET A CONFIG VARIABLE
  public function set($item, $value) {
    $this->config[$item] = $value;
  }
  // ACCESS CONFIG
  public function config($item) {
    return $this->config[$item];
  }
  // MODIFY THE CALL CLASS PROPERTY
  public function modify_call($params) {
    $this->api_call .= $params;
  }
  // ECHO THE CALL FOR DEBUGGING
  public function return_call() {
    return $this->api_call;
  }
  // YOUTUBE VIDEO METHODS
  public function videos($data = 'mutemath', $method = BY_TAG) {
    //---------------------------------------------//
    $this->api_call .= 'videos.'; ///////////////////////
    //---------------------------------------------//
    switch ($method) {
      case BY_TAG:
        if (isset($_GET['tag'])) {
          $keyword = str_replace(" ", "+", $_GET['tag']);
        $this->tag = '&tag=' . $keyword;
        } else {
          $this->tag = '&tag='. $data;
        }
        youtube::modify_call($method . '&dev_id=' . $this->config['api_key'] . $this->tag);
      break;
      default:
        return 'The WaxJelly YouTube API Class only supports retrieving videos by tag.';
      break;
    }
    // CALL DISPLAY
    return youtube::display();
  }
  public function tags_for_video($tags) {
    $tag_links = '';
    // explode
    $x = explode(' ', $tags);
    if (count($x) > 0) {
      foreach ($x as $k => $v) {
        $tag_links .= "<a href=\"{$_SERVER['PHP_SELF']}?tag=$v\">$v</a> ";
      }
    } else { 
      $tag_links = "<a href=\"{$_SERVER['PHP_SELF']}?tag=mutemath\">mutemath</a>";
    }
    return $tag_links;
  }
  // DISPLAY RESULTS
  public function display() {
    // CHECK FOR A NEW PAGE & PER PAGE
    if (isset($_GET['page'])) {
      youtube::set('page', $_GET['page']);
    }
    if (isset($_GET['per_page'])) {
      youtube::set('per_page', $_GET['per_page']);
    }
    // per page, page, prev, next
    // total videos, total pages
    youtube::modify_call('&page=' . youtube::config('page') . '&per_page=' . youtube::config('per_page'));
    // SEND REQUEST
    $this->return = file_get_contents(youtube::return_call());
    $this->xml = new SimpleXMLElement($this->return);
    $this->xml = youtube::xml_to_array($this->xml);
    // CHECK IF THEY'RE ASKING FOR A VIDEO ID
    if (isset($_GET['video_id'])) {
      define('YOUTUBE_VIDEO_ID', $_GET['video_id']);
      // loop through videos to get videos index
      foreach ($this->xml['video_list']['video'] as $indx => $array) {
        if ($array['id'] == $_GET['video_id']) {
          $index = $indx;
          echo $index;
          break;
        } else {
          $index = '';
        }
      }
      // define index
      define('YOUTUBE_VIDEO_INDEX', $index);
    } else {
      define('YOUTUBE_VIDEO_ID', $this->xml['video_list']['video'][0]['id']);
      define('YOUTUBE_VIDEO_INDEX', 0);
    }
    //////////////////////////////////////////
    // CREATE DISPLAY CONSTANTS //
    /////////////////////////////////////////
    define('YOUTUBE_PAGE', youtube::config('page'));
    define('YOUTUBE_PER_PAGE', youtube::config('per_page'));
    $prev = (youtube::config('page') - 1 == 0) ? 1 : youtube::config('page') - 1;
    define('YOUTUBE_PREV_PAGE', $prev . $this->tag);
    define('YOUTUBE_NEXT_PAGE', youtube::config('page') + 1 . $this->tag);
    define('YOUTUBE_TOTAL_VIDEOS', $this->xml['video_list']['total']);
    define('YOUTUBE_TOTAL_PAGES', ceil($this->xml['video_list']['total'] / youtube::config('per_page')));
    // CONVERT FROM SIMPLEXML OBJECT TO ARRAY
    return $this->xml;
  }
}
?>

Het kan nu alleen nog zijn dat er fouten in index.php verschijnen.
 
Ik heb hem toegevoegt en hij werkt helemaal, ook de zoekfunctie.

Hij geeft geen fouten meer aan :thumb:

Heel erg bedankt voor je hulp :thumb::thumb:;):thumb::thumb:

Groetjes Tom

(http://www.tombalfoort.com/media (Voor als je het online wilt zien) hij wordt dan wel doorgelinkt omdat ik allemaal **** te zien krijg ik het adres bij helpmij.nl)
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan