TweetInvi 不检索推文的图片

TweetInvi does not retrieve tweet's picture

我正在使用以下代码阅读推文,它工作正常,但媒体对象始终为空,即使推文有图片,但如果推文有视频而不是图片,它工作正常!

            var stream = userClient.Streams.CreateFilteredStream();
            stream.TweetMode = Tweetinvi.TweetMode.Extended;
            var twitterUser = await userClient.Users.GetUserAsync(username);
            stream.AddFollow(twitterUser);
            stream.MatchingTweetReceived += (sender, eventReceived) =>
            {
                
                if(!eventReceived.Tweet.Retweeted)
                    Console.WriteLine(eventReceived.Tweet);
            };

            await stream.StartMatchingAllConditionsAsync();

我正在调试每条推文并验证每条推文在 Twitter 网站上都有图片。

ITweetMedia 成员是 List<IMediaEntity>。此列表可能为空。使用下面的代码,我能够收到包含 IMediaEntity 个对象的 Media 成员的推文:

static async Task Main(string[] args)
{
    Task task = Task.Run(() => BeginTweetStream());
    await task;
}

public static async Task BeginTweetStream()
{
    string userName = "SomeName";
    int i = 0;
    TwitterClient userClient = new TwitterClient("string", "string", "string", "string"); //where the strings are credentials
    var stream = userClient.Streams.CreateFilteredStream();
    stream.TweetMode = Tweetinvi.TweetMode.Extended;
    var twitterUser = await userClient.Users.GetUserAsync(userName);
    stream.AddTrack("SomeTrack");
    stream.MatchingTweetReceived += (sender, eventReceived) =>
    {
        if (eventReceived.Tweet.Media != null && eventReceived.Tweet.Media.Any() && !eventReceived.Tweet.Retweeted)
        {
            Console.WriteLine($"Tweet with {eventReceived.Tweet.Media.Count()} media found!");

            foreach (Tweetinvi.Models.Entities.IMediaEntity media in eventReceived.Tweet.Media)
            {
                Console.WriteLine($"Media type: {media.MediaType} Link: {media.URL}");
            }

            ++i;
        }

        if (i == 99) //stop after 100 tweets with media
        {
            stream.Stop();
            Console.WriteLine("Complete! Press any key to exit.");
            Console.Read(); 
        }
    };

    await stream.StartMatchingAllConditionsAsync();
}

控制台输出:

你可以查看IMediaEntity.MediaType成员,看看它是什么媒体。我还没有找到可以将其设置为什么值的文档,但到目前为止,我已经看到:

  • photo
  • video
  • animated_gif

请注意,IMediaEntity 对象的 URL 成员是推文本身的 link。如果您在寻找图片本身,MediaURLMediaURLHttps 将仅包含图片的 link(对于视频和动画 GIF,这些成员是缩略图的 link图片代替)。