Youtube API v2.0 video stream link problem

Started on the old forum in July 2013 · view the original in the archive · old links redirect here

2 replies · 606 views · started 13 years ago · 1 min read

2 participants
modfiles Developer · 200 posts #1

Hi, I'm trying to migrate a youtube script i found here to Youtube API version 2. Everything is kinda ok except for my view.php file There are certain videos that doesnt have a 3GP or MP4 mobile stream and with that I'm having

Fatal error: Call to a member function attributes() on a non-object in C:\wamp\www\view.php on line 29

Line 29 is

/* Get 3GP STREAM URL */
/* THIS IS LINE 29 */ $attrs = $media->group->content[1]->attributes();
$obj->tgpp = $attrs['url'];

I try to make a conditional statement to check if 3GP/MP4 stream link is available using empty and isset function

if (!empty($media->group->content[1]->attributes())) {
	$attrs = $media->group->content[1]->attributes();
	$obj->tgpp = $attrs['url'];
} else { echo "";}
if (isset($media->group->content[1]->attributes())) {
	$attrs = $media->group->content[1]->attributes();
	$obj->tgpp = $attrs['url'];
} else { echo "";}

both throw an error

Fatal error: Can't use method return value in write context in C:\wamp\www\view.php on line 29

with this PHP

if ($media->group->content[1]->attributes() == "") { echo ""; }
		else {
			$attrs = $media->group->content[1]->attributes();
			$obj->tgpp = $attrs['url'];
		}

throw an error of

Fatal error: Call to a member function attributes() on a non-object in C:\wamp\www\view.php on line 29

Heres the VIEW.PHP

<?php
header("Content-type: text/html; charset=UTF-8");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

/* Function to parse a video <entry> */
function parseVideoEntry($entry)  {
	$obj= new stdClass;
			/* Get author name and feed URL */
			$obj->author = $entry->author->name;
			$obj->authorURL = $entry->author->uri;
			
			/* Geet video publish date */
			$obj->publish = $entry->published;
			
			/* Get nodes in media: namespace for media information */
			$media = $entry->children('http://search.yahoo.com/mrss/');
			$obj->title = $media->group->title;
			$obj->description = $media->group->description;
			
			/* Get video category */
			$attrs = $media->group->category->attributes();
			$obj->category = $attrs['label'];

			/* Get FLV STREAM URL */
			$attrs = $media->group->content[0]->attributes();
			$obj->flv = $attrs['url'];

			/* Get 3GP STREAM URL */
			$attrs = $media->group->content[1]->attributes();
			$obj->tgpp = $attrs['url'];

			/* Get MP4 STREAM URL */
			$attrs = $media->group->content[2]->attributes();
			$obj->mp4 = $attrs['url'];
			
			/* Get video thumbnail */
			$attrs = $media->group->thumbnail[0]->attributes();
			$obj->thumbnailURL = $attrs['url'];  
			
			/* Get <yt:duration> node for video length */
			$yt = $media->children('http://gdata.youtube.com/schemas/2007');
			$attrs = $yt->duration->attributes();
			$obj->length = $attrs['seconds']; 
				
			/* Get <yt:stats> node for viewer statistics */
			$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
			if ($yt->statistics)
			{
				$attrs = $yt->statistics->attributes();
				$obj->viewCount = $attrs['viewCount']; 
			}
			else
			{
				$obj->viewCount = 0;
			}

			//LIKES get <yt:rating> node for number of likes statistics
			//$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
			if ($yt->rating)
			{
				$attrs = $yt->rating->attributes();
				$obj->numLikes = $attrs['numLikes']; 
			}
			else
			{
				$obj->numLikes = 0; 
			}

			//DISLIKES get <yt:rating> node for number of dislikes statistics
			//$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
			if ($yt->rating) 
			{		
				$attrs = $yt->rating->attributes();
				$obj->numDislikes = $attrs['numDislikes'];
			} else 
			{
				$obj->numDislikes = 0; 
			}
	return $obj;
} // close funcion parseVideoEntry
		
		
		
		
			/* Get video ID from $_GET  */
			!isset($_GET['id']) ? die ('ERROR: Missing video ID') : $vid = $_GET['id'];

			/* Set video data feed URL */
			$feedURL = 'http://gdata.youtube.com/feeds/api/videos/'.$vid.'?v=2';
			
			/* Read feed into SimpleXML object */
			$entry = simplexml_load_file($feedURL);
			
			/* Parse video entry */
			 $video = parseVideoEntry($entry);

			 
			 
?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?=$video->title?></title>
<link href="./style.css" rel="stylesheet" type="text/css" />
</head>
<ul>
	<li>Stream:</li>
	<li><a href="<?=$video->tgpp?>">3GP</a></li>
	<li><a href="<?=$video->mp4?>">MP4</a></li>
	<li><a href="<?=$video->flv?>">Youtube Player</a></li>
</ul>

Problem Fix. Thanks

charith7788 Developer · 51 posts #2

bro youtube is being changing their api versions to v 3.0, there are no mp4 stream link for v2, only they provide 3gp hi quality & low quality stream links, i also have this problem i use youtube developers feed api s but there have a problem. Look here stream links are here but they dont work, i think the best place you have to learn youtube is youtube developer

modfiles Developer · 200 posts #3

issue of stream link for API v2.0 is being discussed here and hopefull they'll fix it asap not having mp4 stream links is ok with coz if the user can stream mp4, then it also has a possibilty of streaming using flash i find API v3 not stable and few or lots of bug as of now.

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close