YouTube API适用于localhost,在服务器上失败

时间:2018-03-07 06:00:00

标签: php api youtube youtube-data-api

我一直在编写代码来从YouTube Data API v3中获取统计数据。在localhost上测试时,一切正常。但是当我将代码上传到我的服务器时,页面根本无法加载。

无论是从php还是在html源代码中都没有显示任何错误。没有。

这是代码中断的地方:

function ytgetvidnfo($inservice, $yid)
{
    $response = $inservice->videos->listVideos('snippet,contentDetails,status,statistics',
                array('id' => $yid ));
    return $response;
}
$searchResponse = ytgetvidnfo($service, $ytl); 

我尝试使用Google自己在Google API上提供的代码替换它,以防万一我搞砸了:

function videosListById($service, $part, $params) 
{
    $params = array_filter($params);
    $response = $service->videos->listVideos(
        $part,
        $params
    );

    print_r($response);
}

videosListById($service,'snippet,contentDetails,status,statistics',array('id' => $ytl));

使用这两个我得到相同的结果:在localhost上正常工作,但在服务器上中断。 HTML源代码显示它会在<BODY>代码后停止。

我可以通过发出以下内容来进一步查明问题:

print_r($client); ==&gt;适用于localhost&amp;在线

print_r($service); ==&gt;仅适用于localhost

所以看起来它没有设法获取视频信息......但为什么呢?

我注意到其他人在2014年提出了类似的问题,但没有明确答案:

Google Youtube API v3 (using public API key) not working on server but it works on localhost

0 个答案:

没有答案
相关问题