[英]Pinterest api returns null when it's called by wp_remote_get
Pinterest api works fine in the browser side to show share count for a specific URL as seen here for Google . Pinterest api在浏览器端可以很好地显示特定URL的共享计数,如此处的Google所示 。
But when I try to call it from wp_remote_get function of Wordpress, it returns null: 但是,当我尝试从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
I want to underline that, this function block works fine when I try to get share counts of Google, Facebook or Twitter. 我想强调一点,当我尝试获取Google,Facebook或Twitter的共享计数时,此功能块可以正常工作。
I also tried wp_remote_post, nothing changed with the response. 我也尝试过wp_remote_post,响应没有任何变化。
OK, I found an answer for this problem. 好的,我找到了这个问题的答案。 The wp_remote_get function returns an array which has a body.
wp_remote_get函数返回具有主体的数组。 But the wp_remote_retrieve_body function can't convert it into a string since it's in the form of a javascript callback (I guess).
但是wp_remote_retrieve_body函数无法将其转换为字符串,因为它采用的是JavaScript回调形式(我想)。
When I get the body directly from the response of the first array and removed the callback function as told here , I got the response json. 当我直接从第一个数组的响应获取主体并按此处所述删除回调函数时,我得到了响应json。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.