Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Ruby
xdk
Paginate through X API v2 results lazily using Ruby Enumerators.
pagination_token
next_token
Enumerator
meta.next_token
require "xdk" client = Xdk::Client.new(bearer_token: ENV.fetch("X_BEARER_TOKEN")) # Fetch at most 3 pages lazily client.posts.search_recent(query: "ruby lang:en", max_results: 25).take(3).each do |page| (page["data"] || []).each do |post| puts "#{post['id']}: #{post['text']}" end end
first_page = client.posts.search_recent(query: "ruby lang:en", max_results: 10).first
client.posts.search_recent(query: "ruby lang:en", max_results: 25) do |page| puts "Got #{(page['data'] || []).length} posts" break if page.dig("meta", "result_count").to_i < 25 end