【问题标题】:Google feed api not returning results with php in wordpressGoogle feed api没有在wordpress中使用php返回结果
【发布时间】:2013-10-16 23:45:12
【问题描述】:

我正在尝试在我的 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 用户。我一直在寻找使用 google feed api 的插件,但一无所获。所以我决定尝试使用谷歌提供的代码。

我非常感谢任何建议。谢谢

【问题讨论】:

    标签: php ajax wordpress curl google-feed-api


    【解决方案1】:

    空白页表示存在致命或解析错误,并且在 PHP 设置中禁用了错误报告。看到这个:How to get useful error messages in PHP?

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多