Pinterest-如何显示最新的图钉(图像和标题)? [英] Pinterest - how to display latest pin (image and title)?

查看:120
本文介绍了Pinterest-如何显示最新的图钉(图像和标题)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以与Pin Widget相似的格式在Pinterest上的板上显示最新图钉的图像和标题,但它必须动态显示最新添加的图钉,而无需进行硬编码.

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.

我需要使用PHP,还是可以用js完成?

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

我更喜欢js,但我看不到如何限制由Profile和Board小部件返回的图像/销钉,或者为Pin It小部件动态加载图像.

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.

我也尝试过RSS feed(使用下面的代码),但是当设置为显示1时,这似乎显示随机的图钉(我可以删除图钉,它仍然会显示).

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

推荐答案

有两种方法可以做到这一点.正确的方法和破解的方法.

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

正确的方法是使用新的公共 Pinterest API .您具有用户登录名,然后获取他们的密码.您可以更改字段以包括所有想要返回的部分. 此处.

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

一种破解方法是使用用于Pinterest小部件的未公开的API.尽管通常是按日期顺序排列的,但不能保证按日期顺序排列,并且将来可能在任何时间点更改或停止存在.您可以通过替换用户名和jsonp回调来ping这样的url.

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>

这篇关于Pinterest-如何显示最新的图钉(图像和标题)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆