How do I read tweets.data.data from twitter-api-v2?
That is the raw current page held inside the paginator object. You usually want the paginator itself, which iterates every page for you, or its .tweets array for the page you are on.
The twitter-api-v2 library does not return a plain response from a search. It returns a paginator, and tweets.data is the raw API payload of the page it is currently holding, which is why the second .data appears. Reading it works, but it only ever gives you one page and it breaks the moment the library changes its internals.
Two things to use instead:
JAVASCRIPT
const paginator = await client.v2.search('xcrop', { max_results: 100 }) // The current page, already unwrapped. console.log(paginator.tweets.length) // Every page, fetched as you go. for await (const tweet of paginator) { console.log(tweet.id, tweet.text) }
Watch the rate limit when you iterate
The async iterator keeps requesting until the result set runs out, so a broad query can spend an entire 15 minute window in a few seconds. Bound it by a count you decide, not by waiting for the iterator to stop.