Pinterest Followers display

2019-04-02 07:29发布

问题:

How would I go about showing my Pinterest followers in Wordpress? I tried this but it only displays the button letting users to follow my account, nothing about my followers.

Presumably, I can do this using the Pinterest API, but I'm unsure where to start.

Any help would be appreciated.

回答1:

Yes, you can use the Pinterest API. Install curl and use that in a PHP script. Example:

$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);

It's supposed to return something like this note that """yourname""" is your Pinterest account name:

{
"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
}
}

Since this returns a json string you´ll need to decode it.

$count = json_decode($json, true);
$count = $count['meta']['count'];

I don't know if curl is available when hosting your site on Wordpress but might be worth a try. In your case the "count" in that string is probably what you want.



回答2:

Maybe it will be helpful for someone. To get the number of account followers:

<?php
$metas = get_meta_tags('http://pinterest.com/pinterest/');
print_r($metas['pinterestapp:followers']);


回答3:

I managed to do it with this plugin http://wordpress.org/plugins/pinterest-badge/

I added it as a widget. I made the number of pins = 0 and no title.

See screenshot below:

You can edit the styles to your liking as well as change the "Followed by..." text in the plugin files!