I am currently using RestTemplate to make requests to the Twitter Web API. Here is the code (partial omission):
String url = "https://twitter.com/i/api/graphql/WzJjibAcDa-oCjCcLOotcg/UserTweets";
UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(url);
if (StringUtils.isNotBlank(cursor)) {
uriBuilder.queryParam("variables", "{\"userId\":\"" + userId + "\",\"count\":40,\"cursor\":\"" + cursor + "\",\"includePromotedContent\":true,\"withQuickPromoteEligibilityTweetFields\":true,\"withVoice\":true,\"withV2Timeline\":true}");
} else {
uriBuilder.queryParam("variables", "{\"userId\":\"" + userId + "\",\"count\":40,\"includePromotedContent\":true,\"withQuickPromoteEligibilityTweetFields\":true,\"withVoice\":true,\"withV2Timeline\":true}");
}
uriBuilder.queryParam("features", "{\"rweb_lists_timeline_redesign_enabled\":false,\"blue_business_profile_image_shape_enabled\":true,\"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,\"tweetypie_unmention_optimization_enabled\":true,\"vibe_api_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,\"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\":false,\"interactive_text_enabled\":true,\"responsive_web_text_conversations_enabled\":false,\"longform_notetweets_rich_text_read_enabled\":true,\"longform_notetweets_inline_media_enabled\":false,\"responsive_web_enhance_cards_enabled\":false}");
URI finalUrl = uriBuilder.build().encode().toUri();
HttpEntity<?> requestEntity = new HttpEntity<>(headers);
ResponseEntity<String> finalResponse = restTemplate.exchange(finalUrl, HttpMethod.GET, requestEntity, String.class);
However, I found that when the cursor parameter contains the characters '+' or '/', my pagination requests fail, and it returns the content of the first page. I have tried encoding the '+' or '/' characters in advance, but it still doesn't work.
The version of RestTemplate is spring-web:5.1.7.RELEASE