是的,您可以使用 Pinterest API。安装 curl 并在 PHP 脚本中使用它。示例:
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, 'http://pinterestapi.co.uk/"""yourname"""/likes');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
$json = curl_exec($ch);
curl_close($ch);
它应该返回类似于“你的名字”是你的 Pinterest 帐户名称的注释:
{
"body": [
{
"href": "http://pinterest.com/pin/150026231307331200/",
"src": "http://media-cache-ec3.pinterest.com/upload/228979962274567868_qVshovBS_b.jpg",
"desc": "#london",
"user": "Louise Earl",
"via": "Kris Mitchell",
"board": "Ideal"
},
{
"href": "http://pinterest.com/pin/287104544965407998/",
"src": "http://media-cache-ec8.pinterest.com/upload/287104544965407998_z3kbynbX_b.jpg",
"desc": "hipsters vs old people",
"user": "Lucy Foulkes",
"via": false,
"board": "cool"
}
],
"meta": {
"count": 2
}
}
由于这会返回一个 json 字符串,因此您需要对其进行解码。
$count = json_decode($json, true);
$count = $count['meta']['count'];
我不知道在 Wordpress 上托管您的网站时是否可以使用 curl,但可能值得一试。在您的情况下,该字符串中的“计数”可能就是您想要的。