diff --git a/Samples/LinqToTwitter6/Console/ConsoleDemo.CSharp/ConsoleDemo.CSharp/SearchDemos.cs b/Samples/LinqToTwitter6/Console/ConsoleDemo.CSharp/ConsoleDemo.CSharp/SearchDemos.cs index ea1b3970..f71c952f 100644 --- a/Samples/LinqToTwitter6/Console/ConsoleDemo.CSharp/ConsoleDemo.CSharp/SearchDemos.cs +++ b/Samples/LinqToTwitter6/Console/ConsoleDemo.CSharp/ConsoleDemo.CSharp/SearchDemos.cs @@ -160,6 +160,7 @@ static async Task DoPagedSearchAsync(TwitterContext twitterCtx) static async Task DoRecentSearchAsync(TwitterContext twitterCtx) { string searchTerm = "\"LINQ to Twitter\" OR Linq2Twitter OR LinqToTwitter OR JoeMayo"; + searchTerm = "Twitter"; // default is id and text and this also brings in created_at and geo string tweetFields = @@ -177,6 +178,7 @@ static async Task DoRecentSearchAsync(TwitterContext twitterCtx) (from search in twitterCtx.TwitterSearch where search.Type == SearchType.RecentSearch && search.Query == searchTerm && + search.MaxResults == 100 && search.TweetFields == TweetField.AllFieldsExceptPermissioned && search.Expansions == ExpansionField.AllTweetFields && search.MediaFields == MediaField.AllFieldsExceptPermissioned && diff --git a/src/LinqToTwitter6/LinqToTwitter/Search/TwitterSearchRequestProcessor.cs b/src/LinqToTwitter6/LinqToTwitter/Search/TwitterSearchRequestProcessor.cs index 3d86faac..bf639a0a 100644 --- a/src/LinqToTwitter6/LinqToTwitter/Search/TwitterSearchRequestProcessor.cs +++ b/src/LinqToTwitter6/LinqToTwitter/Search/TwitterSearchRequestProcessor.cs @@ -267,7 +267,8 @@ TwitterSearch JsonDeserialize(string responseJson) { Converters = { - new JsonStringEnumConverter() + new JsonStringEnumConverter(), + new TweetMediaTypeConverter() } }; TwitterSearch? search = JsonSerializer.Deserialize(responseJson, options); diff --git a/src/LinqToTwitter6/LinqToTwitter/Tweet/TweetMedia.cs b/src/LinqToTwitter6/LinqToTwitter/Tweet/TweetMedia.cs index 282689ba..03da2bd0 100644 --- a/src/LinqToTwitter6/LinqToTwitter/Tweet/TweetMedia.cs +++ b/src/LinqToTwitter6/LinqToTwitter/Tweet/TweetMedia.cs @@ -34,7 +34,7 @@ public record TweetMedia public object? OrganicMetrics { get; init; } /// - /// URL to video preview image + /// URL to animated GIF and video preview image /// [JsonPropertyName("preview_image_url")] public string? PreviewImageUrl { get; init; } @@ -50,9 +50,16 @@ public record TweetMedia /// /// Type of media - e.g. gif, photo, or video /// + [JsonConverter(typeof(TweetMediaTypeConverter))] [JsonPropertyName("type")] public TweetMediaType Type { get; init; } + /// + /// URL to photo preview image + /// + [JsonPropertyName("url")] + public string? Url { get; init; } + /// /// Width in pixels /// diff --git a/src/LinqToTwitter6/LinqToTwitter/Tweet/TweetMediaTypeConverter.cs b/src/LinqToTwitter6/LinqToTwitter/Tweet/TweetMediaTypeConverter.cs new file mode 100644 index 00000000..13039300 --- /dev/null +++ b/src/LinqToTwitter6/LinqToTwitter/Tweet/TweetMediaTypeConverter.cs @@ -0,0 +1,32 @@ +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace LinqToTwitter +{ + public class TweetMediaTypeConverter : JsonConverter + { + public override TweetMediaType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + return reader.GetString() switch + { + "animated_gif" => TweetMediaType.AnimatedGif, + "photo" => TweetMediaType.Photo, + "video" => TweetMediaType.Video, + _ => TweetMediaType.None + }; + } + + public override void Write(Utf8JsonWriter writer, TweetMediaType value, JsonSerializerOptions options) + { + writer.WriteStringValue( + value switch + { + TweetMediaType.AnimatedGif => "animated_gif", + TweetMediaType.Photo => "photo", + TweetMediaType.Video => "video", + _ => "" + }); + } + } +} \ No newline at end of file diff --git a/src/LinqToTwitter6/LinqToTwitter/Tweet/TweetRequestProcessor.cs b/src/LinqToTwitter6/LinqToTwitter/Tweet/TweetRequestProcessor.cs index ebf50e18..0b541aed 100644 --- a/src/LinqToTwitter6/LinqToTwitter/Tweet/TweetRequestProcessor.cs +++ b/src/LinqToTwitter6/LinqToTwitter/Tweet/TweetRequestProcessor.cs @@ -357,7 +357,8 @@ TweetQuery JsonDeserialize(string responseJson) { Converters = { - new JsonStringEnumConverter() + new JsonStringEnumConverter(), + new TweetMediaTypeConverter() } }; TweetQuery? tweet = JsonSerializer.Deserialize(responseJson, options);