API Feed不给我实时站点的数据


API Feed Doesn't Give Me Data on Live Site

所以我有一个问题与YouTube API Feed。

在我们的实时网站上,它没有打印feed的数据,但是当我去我们的开发人员服务器时,一切都打印正确。

下面是一个基本的测试页面作为例子:http://www.fleetistics.com/videos/test.php

我什么也没看见。

下面是我应该看到的代码片段:

SimpleXMLElement Object
(
    [id] => tag:youtube.com,2008:video:wzE9T5iy00Y
    [published] => 2013-03-25T19:13:32.000Z
    [updated] => 2013-06-05T13:29:37.000Z
    [category] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [scheme] => http://schemas.google.com/g/2005#kind
                            [term] => http://gdata.youtube.com/schemas/2007#video
                        )
                )
            [1] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [scheme] => http://gdata.youtube.com/schemas/2007/categories.cat
                            [term] => Autos
                            [label] => Autos & Vehicles
                        )
                )
        )
    [title] => GPS Tracker Used by Action Lock and Safe
    [content] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [type] => application/x-shockwave-flash
                    [src] => https://www.youtube.com/v/wzE9T5iy00Y?version=3&f=videos&app=youtube_gdata
                )
        )
下面是我在test.php页面上使用的代码:
<?php
    $entryURL = 'https://gdata.youtube.com/feeds/api/videos/wzE9T5iy00Y?v=2';
    $feed = simplexml_load_file($entryURL);
?>
<pre><?php print_r($feed); ?></pre>

这个基本的例子只使用了"video "提要,但是我在所有提要中都遇到了同样的问题。

这些提要在周五的时候还能正常工作,所以在这段时间里发生了什么。

我已经排除了它可能是编程错误的可能性,因为在我提供的示例中,我去掉了所有内容,只留下了最少的部分。另外,同样的代码在开发服务器上也能很好地工作。

我不认为这是YouTube的API,因为我没有看到任何重大的公告,我看到的其他提要工作得很好。

所以我认为这是我的网站或我的帐户的问题。我得到的印象是我的帐户有问题,因为我的网站上使用其他应用程序的其他提要工作正常。

我如何解决这个问题,或者进一步解决这个问题,以便我可以解决它?

这听起来(看起来)很可疑,就像php标志allow_url_fopen在您的生产服务器上被关闭了。如果您可以访问php.ini文件,您可以检查该标志(它需要打开以允许simplexml_load_file加载远程数据)。如果它是一个托管环境,您没有访问权限,您可以通过编写这样的例程来检查:

if( ini_get('allow_url_fopen') ) {
   echo "it's on!";
} 
else {
   echo "it's off!";
}

如果这是问题所在,并且您没有权限将其重新打开,您可以使用curl:

function curl_get_contents ($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}
$entryURL = 'https://gdata.youtube.com/feeds/api/videos/wzE9T5iy00Y?v=2';
$feed = simplexml_load_file(curl_get_contents($entryURL));

如果这不是问题,检查您的日志,看看simplexml_load_file是否抛出任何错误。