Google feed api在wordpress中不返回php的结果



我正在尝试在我的WordPress网站中使用Google Feed API。 我用一个插件启用了 PHP,它允许我在页面中输入 PHP 代码。 我的托管服务提供商还确认他们已启用 Curl。

这是我尝试运行的代码,我从谷歌开发人员网站获得(https://developers.google.com/feed/v1/jsondevguide#basic_query(

<?php 
$url = "https://ajax.googleapis.com/ajax/services/feed/find?v=1.0&q=iphone5&  userip=2.96.214.41";
// sendRequest
// note how referer is set manually
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, http://www.iweb21.com);
$body = curl_exec($ch);
curl_close($ch);
// now, process the JSON string
$json = json_decode($body);
// now have some fun with the results...
?>

我没有得到任何结果,只是一个空白页。

我不是PHP程序员。 只是一个新手WordPress用户。 我一直在寻找一个插件来使用谷歌提要API,但一无所获。 所以我决定尝试使用谷歌提供的代码。

我将非常感谢任何建议。

空白页表示存在致命或解析错误,并且在 PHP 设置中禁用了错误报告。看看这个: 如何在PHP中获取有用的错误消息?

在您的特定情况下,引用字符串不括在引号中,并生成解析错误。替换为:

curl_setopt($ch, CURLOPT_REFERER, 'http://www.iweb21.com');

最新更新