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

本文是小编为大家收集整理的关于Pinterest-how to display latest pin (image and title)?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我想在 Pinterest 上以与 Pin 小部件类似的格式显示最新 Pin 图的图像和标题,但它必须动态显示最新添加的 Pin 图而不是硬编码.

我需要使用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);

推荐答案

有两种方法可以做到这一点.正确的方式和黑客的方式.

正确的方法是使用新的公共 Pinterest API.您有一个用户登录,然后获取他们的密码.您可以更改字段以包含您想要返回的所有部分.获取 PDK 的链接是这里.

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.

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

本文地址:https://www.itbaoku.cn/post/1937771.html

问题描述

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

推荐答案

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>