我想在Pinterest上以与Pin Widget类似的格式显示最新引脚的图像和标题,但它必须动态显示最新添加的引脚而不是硬编码。
我是否需要使用PHP,还是可以使用js完成?
我更喜欢js,但我看不出如何限制Profile和Board小部件返回的图像/引脚,或动态加载Pin It小部件的图像。
我也尝试了RSS提要(使用下面的代码),但是当设置为显示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);
答案 0 :(得分:0)
有两种方法可以做到这一点。正确的方式和黑客的方式。
正确的方法是使用新的公开Pinterest API。您有用户登录,然后获取其引脚。您可以更改字段以包含您想要的所有部分。获取PDK的链接是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。不保证按日期排序,但通常是,并且可以在将来的任何时间点改变或停止存在。您可以通过替换username和jsonp回调来ping这样的URL。
https://api.pinterest.com/v3/pidgets/users/<username>/pins/?callback=<callback>