node-twitter-api-v2 icon indicating copy to clipboard operation
node-twitter-api-v2 copied to clipboard

TypeError - Cannot read properties of undefined (reading 'reset')

Open maximedupre opened this issue 2 years ago • 1 comments

Describe the bug I get this error pretty frequently:

TypeError: Cannot read properties of undefined (reading 'reset') File "/app/node_modules/twitter-api-v2/dist/paginators/TwitterPaginator.js", line 16, col 43, in UserTimelineV1Paginator.get _isRateLimitOk [as _isRateLimitOk] const resetDate = this._rateLimit.reset * 1000; File "/app/node_modules/twitter-api-v2/dist/paginators/TwitterPaginator.js", line 73, col 44, in UserTimelineV1Paginator.fetchLast while (resultCount < count && this._isRateLimitOk) { File "/app/node_modules/twitter-api-v2/dist/paginators/TwitterPaginator.js", in runMicrotasks File "node:internal/process/task_queues", line 96, col 5, in processTicksAndRejections File "/app/build/server/_app/immutable/chunks/twitter-9b061443.js", line 169, col 29, in fetchLast3200TweetsFromUser userTimelineV1Paginator = await userTimelineV1Paginator.fetchLast(3e3); File "/app/build/server/_app/immutable/chunks/profile-ab-77c2f8fa.js", line 56, col 28, in setProfile const last3200Tweets = await fetchLast3200TweetsFromUser(twitterUserId, twitterAccessToken, twitterAccessTokenSecret);

This is my abstraction that is calling twitter-api-v2

export async function fetchLast3200TweetsFromUser(
    userId: string,
    accessToken: string,
    accessSecret: string,
) {
    const userClient = createUserClient(accessToken, accessSecret);

    let userTimelineV1Paginator = await userClient.readOnly.v1.userTimeline(
        userId,
        { count: 200 },
    );

    userTimelineV1Paginator = await userTimelineV1Paginator.fetchLast(3000);

    return userTimelineV1Paginator.tweets;
}

The error originates at this line: userTimelineV1Paginator = await userTimelineV1Paginator.fetchLast(3000);

Version

  • Node.js version: v16.14.0
  • Lib version: "twitter-api-v2": "^1.12.3"
  • OS (especially if you use Windows): macOS 12.5

maximedupre avatar Aug 03 '22 00:08 maximedupre

Hi, This may be a problem with the parsing of rate limit headers. Either Twitter do not return rate limit info for this endpoint, or it's a parsing problem elsewhere. I'll take a look when I have time.

alkihis avatar Aug 03 '22 20:08 alkihis

Fix available in 1.12.5 :)

alkihis avatar Aug 15 '22 19:08 alkihis