Last active
December 22, 2015 10:15
-
-
Save zoerooney/2299f1623ed03e5ffd69 to your computer and use it in GitHub Desktop.
Pinterest via RSS feed and Google Feed API, as discussed here: http://zoerooney.com/blog/tutorials/display-a-pinterest-feed-almost-anywhere-via-rss/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="pinfeed"></div> | |
<script type="text/javascript" src="https://www.google.com/jsapi"></script> | |
<!-- ref: https://developers.google.com/feed/v1/devguide --> | |
<script type="text/javascript"> | |
google.load('feeds', '1'); | |
function initialize() { | |
var feed = new google.feeds.Feed('https://www.pinterest.com/username/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); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Zoe,
When i change the setNumEntries value to let's say 4 it loads the fourth image and not 4 images. Is there something else I need to change to get a result which displays more than one image?