Pinterest - how to display latest pin (image and title)?

霸气de小男生 提交于 2019-12-25 03:13:13

问题


I'd like to display the image and title of the latest pin from a board on Pinterest, in a similar format to the Pin Widget, but it has to dynamically display the latest added pin and not be hard coded.

Do I need to use PHP, or can this be done with js?

I'd prefer js but I can't see how to either, limit the images/pins returned by the Profile and Board widgets, or dynamically load an image for the Pin It widget.

I've also tried the RSS feed (using the code below), but this seems to display random pins (I can delete a pin and it will still display) when set to display 1:

google.load('feeds', '1');

function initialize() {
var feed = new google.feeds.Feed('https://www.pinterest.com/[username]/[board]/feed.rss'); // update username

feed.setNumEntries(1); // set number of results to show

feed.load(function(result) {
        if (!result.error) {
            var container = document.getElementById('pinfeed'); // look for our display container

            for (var i = 0; i < result.feed.entries.length; i++) { // loop through results

                var entry   = result.feed.entries[i],
                content = entry.content, // get "content" which includes img element
                regex   = /src="(.*?)"/, // look for img element in content
                src     = regex.exec(content)[1]; // pull the src out, 

                // put our link to the pin with img into our container:
                container.innerHTML = '<a href="'+ entry.link + '" target="_blank"><img src="'+ src + '" /></a>';
            }
        }
});
}
google.setOnLoadCallback(initialize);

回答1:


There are two ways to do this. The right way and the hack way.

The right way is to use the new public Pinterest API. You have a user login and then fetch their pins. You can change the fields to include all the pieces you want back. The link to get PDK is here.

PDK.login({scope:'read_public'}, function() {
    if (session) {
        PDK.me('pins', {fields: 'created_at,image,note'}, function(pins) {
            ...do something with the pins
        });
    }
});

The hack way to do it is to use the undocumented API used for the Pinterest widgets. It is not guaranteed to be in order of date, though it usually is, and can change or cease to exist at any point in time in the future. You can ping a url like this, by replacing username and the jsonp callback.

https://api.pinterest.com/v3/pidgets/users/<username>/pins/?callback=<callback>



来源:https://stackoverflow.com/questions/33012430/pinterest-how-to-display-latest-pin-image-and-title

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!