将Instagram图片提取到我的网站

时间:2015-03-09 11:11:56

标签: javascript jquery instagram

我正在使用一些JS通过与图像相关联的特定标签来从我的帐户中提取Instagram图像。

我已将其设置为拉入10张图片,但由于某种原因,它似乎在拉入21张。

这几天前工作正常,但突然间它现在不能正常工作而且不知道为什么

这是在线页面http://www.gezzamondo.co.uk/simple.html

// JavaScript Document
$(function() {
var cmdURL, embedImage, onPhotoLoaded, param, tag_name, userid,
    param = {
        access_token: "I'VE REMOVED THIS", // feel free to change it with your own access token
        count: 10 // the total number of images
    },
    tag = 'Gezzamondoportfolio', // your user id. you can find this one out by looking into one of your pictures uri
    tag_name = '#photowall',
    cmdURL = 'https://api.instagram.com/v1/tags/' + tag + '/media/recent?callback=?';

embedImage = function(photo) {
    var a, img;
    img = $('<img/>').attr({
        //'src': photo.images.thumbnail.url,
        //'width': photo.images.thumbnail.width,
        //'height': photo.images.thumbnail.height
        'src': photo.images.standard_resolution.url,
        'width': photo.images.standard_resolution.width,
        'height': photo.images.standard_resolution.height
    });
    a = $('<a />').attr({
        'href': photo.images.standard_resolution.url,
        'target': '_blank',
        'class': 'pull-left'
    }).append(img).appendTo(tag_name);
};

onPhotoLoaded = function(data) {
    var photo, _i, _len, _ref, _results;
    if (data.meta.code === 200 && data.data) {
        _ref = data.data;
        _results = [];
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
            photo = _ref[_i];
            _results.push(embedImage(photo));
        }
        return _results;
    }
 };
 return $.getJSON(cmdURL, param, onPhotoLoaded);
});

1 个答案:

答案 0 :(得分:0)

尝试将count参数添加到您的请求网址中:

cmdURL = 'https://api.instagram.com/v1/tags/' + tag + '/media/recent?count=10&callback=?';

(编辑)你可以在你制作照片的for循环中数到10:

for (_i = 0, _len < 10; _i < _len; _i++) {
photo = _ref[_i];
_results.push(embedImage(photo));}

显然,这不会改变你从Instagram上获得的结果数量,但它会限制你输出到屏幕的数量......