Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lucasborgesdev opened this issue Sep 23, 2021 · 3 comments

Comments

@lucasborgesdev
Copy link

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

@viktor-morin
Copy link

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

@webbipinpal
Copy link

@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
Copy link

viktor-morin commented May 3, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants