stevenschobert/instafeed.js

Does not have details on how to use the filter to search for specific hashtag!

lucasborgesdev opened this issue · 3 comments

Does not have details on how to use the filter to search for specific hashtag of the desired profile, it would be nice to have a hashtag filter to fetch only the tag I want

image

The filter iterate each image, where you can go into the tags array and verify that your tag is there.
If it is, simple retry true, otherwise false

@viktor-morin it is not working for me. I am using the below code. Please check it.

var userFeed = new Instafeed({
get: 'tagged',
tagName: 'tagname',
target: "instafeed-container",
resolution: 'low_resolution',
limit:12,
userId:'3333....',
template:'code here',
accessToken: 'number here',
transform: function(item) {
item.timestamp = new Date(item.timestamp).toLocaleString('en-AU', {
month: 'long',
day: 'numeric'
});
return item;
},
filter: function(image) {
return image.tags.indexOf('[tagnam]') >= 0;
}

});
userFeed.run();

@viktor-morin it is not working for me. I am using the below code. Please check it.

var userFeed = new Instafeed({ get: 'tagged', tagName: 'tagname', target: "instafeed-container", resolution: 'low_resolution', limit:12, userId:'3333....', template:'code here', accessToken: 'number here', transform: function(item) { item.timestamp = new Date(item.timestamp).toLocaleString('en-AU', { month: 'long', day: 'numeric' }); return item; }, filter: function(image) { return image.tags.indexOf('[tagnam]') >= 0; }

});
userFeed.run();

When working with this, I could see that you could iterate each picture and apply your own "filter".
However, the JS version had an limitation of 250 post, which wasn't suitable for us. So I decided to look into the code and implement my own solution in backend, where I iterate all pages, resulting in all post.
See my implementation here in C#.

Sorry I didnt saved the JS implementation.
Good luck!

public async Task<IEnumerable<InstagramPostDto>> GetInstagramPosts()
{
    var token = await GetAccessToken();
    var baseUrl = "https://graph.instagram.com/me/media?fields=caption,media_type,permalink,media_url&limit=100&access_token=";
    var response = await _httpClient.GetAsync($"{baseUrl}{token}");
    if (!response.IsSuccessStatusCode)
        return default;

    var results = new List<InstagramPostDto>();

    var responseJson = await response.Content.ReadAsStringAsync();
    var jObject = JObject.Parse(responseJson);
    var datas = jObject["data"].ToObject<IEnumerable<JObject>>();
    foreach (var data in datas)
        results.Add(new InstagramPostDto { 
            Caption = data["caption"].ToObject<string>(), 
            MediaType = data["media_type"].ToObject<string>(), 
            ThumbnailImageUrl = data["media_url"].ToObject<string>(), 
            Url = data["permalink"].ToObject<string>() });
    

    while (jObject["paging"].ToObject<JObject>().ContainsKey("next"))
    {
        var nextPageUrl = jObject["paging"]["next"].ToObject<string>();
        response = await _httpClient.GetAsync(nextPageUrl);
        if (!response.IsSuccessStatusCode)
            return default;

        responseJson = await response.Content.ReadAsStringAsync();
        jObject = JObject.Parse(responseJson);
        datas = jObject["data"].ToObject<IEnumerable<JObject>>();
        foreach (var data in datas)
            results.Add(new InstagramPostDto
            {
                Caption = data["caption"].ToObject<string>(),
                MediaType = data["media_type"].ToObject<string>(),
                ThumbnailImageUrl = data["media_url"].ToObject<string>(),
                Url = data["permalink"].ToObject<string>()
            });
    }

    return results.Where(r => r.Caption?.ToLowerInvariant()?.Contains("#fusklapp") == true);
}