Search code examples
c#twitterlinq-to-twitter

Linq2Twitter MediaEntity: How to access more than one ImageURL


why is it that the linq2Twitter API only stores one image as a MediaURL in the Entity class even there are surly two images in a particular tweet?

This is the tweet "https://t.co/VoxCtVl2k1" that I am debbugung in the screenshot. It has two pictures but the fully qualified URL is only for the first one accessible?

enter image description here


Solution

  • Please look under ExtendedEntities, which is a newer object in the Twitter API.

    On Search queries, the Twitter API has a bug that hasn't been resolved. Please visit and like the following issue in their forums:

    https://twittercommunity.com/t/search-tweets-endpoint-and-extended-entities/31655

    LINQ to Twitter does support the include_entities parameter, like this:

            Search searchResponse =
                await
                (from search in twitterCtx.Search
                 where search.Type == SearchType.Search &&
                       search.Query == searchTerm &&
                       search.IncludeEntities == true
                 select search)
                .SingleOrDefaultAsync();
    

    As I said earlier, this isn't working. A potential work-around is to use a Status/Lookup query, like this:

            List<Status> tweets =
                await
                (from tweet in twitterCtx.Status
                 where tweet.Type == StatusType.Lookup &&
                       tweet.TweetIDs == "460788892723978241,462758132448362496,460060836967768064"
                 select tweet)
                .ToListAsync();
    

    To make this work, find all of your tweets in the search response that have media and collect their IDs. Then combine those into a comma-separated list and assign to TweetIDs. Remember that you can only do a lookup of 100 IDs at a time.