D
D
Denis Artemiev2015-07-06 23:39:00
YouTube
Denis Artemiev, 2015-07-06 23:39:00

How to fix error when getting data from Youtube api?

Hello, I have this function:

public static function getYoutubeSubscribers($username) {
        $username = trim($username);
        if (!$username)
            return 0;

        $link = 'http://gdata.youtube.com/feeds/api/users/' . strtolower($username); 
        $info = self::curlGetContent($link); 
        $xmlData = str_replace('yt:', 'yt', $info); 
        $xml = new SimpleXMLElement($xmlData); 
        $subs = $xml->ytstatistics['subscriberCount']; 
        return($subs);
    }

Function in Joomla template. On the line $xml = new SimpleXMLElement($xmlData); gives an error message:
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in D:\OpenServer\domains\localhost\buh.tv\templates\it_premiere\icetools\icetool.php:219 Stack trace: #0 D:\OpenServer\domains\localhost\buh.tv\templates\it_premiere\icetools\icetool.php(219): SimpleXMLElement->__construct('No longer avail...') #1 D:\OpenServer\domains\localhost\buh.tv\templates\it_premiere\icetools\layout_vars.php(44): iceTool::getYoutubeSubscribers('icetheme') #2 D:\OpenServer\domains\localhost\buh.tv\templates\it_premiere\index.php(29): require_once('D:\OpenServer\d...') #3 D:\OpenServer\domains\localhost\buh.tv\libraries\joomla\document\html\html.php(531): require('D:\OpenServer\d...') #4 D:\OpenServer\domains\localhost\buh.tv\libraries\joomla\document\html\html.php(591): JDocumentHTML->_loadTemplate('D:\OpenServer\d...', 'index.php') #5 D:\OpenServer\domains\localhost\buh.tv\libraries\joomla\document\html\html.php(414): JDocumentHTML->_fetchTemplate(Array) #6 D:\OpenServer\domains\localhost\buh.tv\includes\application.php(259): JDocumentHTML->parse(Array) #7 D:\OpenServer\domains\localhost\buh.tv\index.php(48): JSite->render() #8 {main} thrown in D:\OpenServer\domains\localhost\buh.tv\templates\it_premiere\icetools\icetool.php on line 219

Because of what it can be and how to solve it?
There are suspicions towards Youtube authentication, can it be?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
frees2, 2015-07-07
@frees2

THIS IS AN OLD API, IT DOESN'T WORK NO LONGER.
An example of how to get v3 api.
www.dulsky.eu/v
In the manuals of Google, everything is written.

M
Michael, 2015-07-06
@Remdev

An exception is thrown that is not caught.
In try ... catch wrap everything.
ps exception due to the fact that the data cannot be parsed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question