【问题标题】:Pinterest api returns null when it's called by wp_remote_getPinterest api 在被 wp_remote_get 调用时返回 null
【发布时间】:2015-01-15 20:40:22
【问题描述】:

Pinterest api 在浏览器端运行良好,可以将特定 URL 的共享计数显示为 seen here for Google。

但是当我尝试从 Wordpress 的 wp_remote_get 函数调用它时,它返回 null:

$url = "http://api.pinterest.com/v1/urls/count.json?url=http://www.google.com";
$response = wp_remote_retrieve_body(wp_remote_get($url, 
    array ('timeout' => 30, 'sslverify' => false ) ) );
var_dump($response); // null

我想强调一点,当我尝试获取 Google、Facebook 或 Twitter 的共享计数时,此功能块可以正常工作。

我也尝试了 wp_remote_post,响应没有任何变化。

【问题讨论】:

    标签: php wordpress pinterest


    【解决方案1】:

    好的,我找到了这个问题的答案。 wp_remote_get 函数返回一个具有主体的数组。但是 wp_remote_retrieve_body 函数无法将其转换为字符串,因为它是 javascript 回调的形式(我猜)。

    当我直接从第一个数组的response中得到body,去掉回调函数as told here,得到的是response json。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-28
      • 1970-01-01
      • 2013-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多