1 // OpenTween - Client of Twitter
2 // Copyright (c) 2023 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
5 // This file is part of OpenTween.
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 // You should have received a copy of the GNU General Public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
25 using System.Collections.Generic;
26 using System.Threading.Tasks;
27 using System.Xml.XPath;
28 using OpenTween.Connection;
30 namespace OpenTween.Api.GraphQL
32 public class HomeLatestTimelineRequest
34 public static readonly string EndpointName = "HomeLatestTimeline";
36 private static readonly Uri EndpointUri = new("https://twitter.com/i/api/graphql/lAKISuk_McyDUlhS2Zmv4A/HomeLatestTimeline");
38 public int Count { get; set; } = 20;
40 public string? Cursor { get; set; }
42 public Dictionary<string, string> CreateParameters()
47 $@"""includePromotedContent"":true,""latestControlAvailable"":true,""requestContext"":""launch""," +
48 $@"""count"":{this.Count}" +
49 (this.Cursor != null ? $@",""cursor"":""{JsonUtils.EscapeJsonString(this.Cursor)}""" : "") +
52 {"responsive_web_graphql_exclude_directive_enabled":true,"verified_phone_label_enabled":false,"creator_subscriptions_tweet_preview_api_enabled":true,"responsive_web_graphql_timeline_navigation_enabled":true,"responsive_web_graphql_skip_user_profile_image_extensions_enabled":false,"c9s_tweet_anatomy_moderator_badge_enabled":true,"tweetypie_unmention_optimization_enabled":true,"responsive_web_edit_tweet_api_enabled":true,"graphql_is_translatable_rweb_tweet_is_translatable_enabled":true,"view_counts_everywhere_api_enabled":true,"longform_notetweets_consumption_enabled":true,"responsive_web_twitter_article_tweet_consumption_enabled":true,"tweet_awards_web_tipping_enabled":false,"freedom_of_speech_not_reach_fetch_enabled":true,"standardized_nudges_misinfo":true,"tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled":true,"rweb_video_timestamps_enabled":true,"longform_notetweets_rich_text_read_enabled":true,"longform_notetweets_inline_media_enabled":true,"responsive_web_media_download_video_enabled":false,"responsive_web_enhance_cards_enabled":false}
57 public async Task<TimelineResponse> Send(IApiConnection apiConnection)
59 var request = new GetRequest
61 RequestUri = EndpointUri,
62 Query = this.CreateParameters(),
63 EndpointName = EndpointName,
66 using var response = await apiConnection.SendAsync(request)
67 .ConfigureAwait(false);
69 var rootElm = await response.ReadAsJsonXml()
70 .ConfigureAwait(false);
72 ErrorResponse.ThrowIfError(rootElm);
74 var tweets = TimelineTweet.ExtractTimelineTweets(rootElm);
75 var cursorTop = rootElm.XPathSelectElement("//content[__typename[text()='TimelineTimelineCursor']][cursorType[text()='Top']]/value")?.Value;
76 var cursorBottom = rootElm.XPathSelectElement("//content[__typename[text()='TimelineTimelineCursor']][cursorType[text()='Bottom']]/value")?.Value;
78 return new(tweets, cursorTop, cursorBottom);