rooteco / tweetscape

the supercharged twitter feed
https://prototype.tweetscape.co
GNU Affero General Public License v3.0
18 stars 2 forks source link

Reset `since_id` if it's more than a week old #421

Closed nicholaschiang closed 2 years ago

nicholaschiang commented 2 years ago

Twitter's recent search API only lets us use a since_id that's less than a week old. If we try to use a since_id that's from any earlier than that, we get the following error:

dev:remix] [error] Handling Twitter API Error: Error: Request failed with code 400 - Invalid Request: One or more parameters to your request was invalid. (see https://api.twitter.com/2/problems/invalid-request)
[dev:remix]     at RequestHandlerHelper.createResponseError (/home/nchiang/repos/tweetscape/node_modules/twitter-api-v2/dist/client-mixins/request-handler.helper.js:99:16)
[dev:remix]     at RequestHandlerHelper.onResponseEndHandler (/home/nchiang/repos/tweetscape/node_modules/twitter-api-v2/dist/client-mixins/request-handler.helper.js:248:25)
[dev:remix]     at Gunzip.emit (node:events:527:28)
[dev:remix]     at endReadableNT (node:internal/streams/readable:1345:12)
[dev:remix]     at processTicksAndRejections (node:internal/process/task_queues:83:21)
[dev:remix] [error] Full error object: {
[dev:remix]   "type": "response",
[dev:remix]   "code": 400,
[dev:remix]   "error": {
[dev:remix]     "errors": [
[dev:remix]       {
[dev:remix]         "parameters": {
[dev:remix]           "since_id": [
[dev:remix]             "1519056945277198339"
[dev:remix]           ]
[dev:remix]         },
[dev:remix]         "message": "'since_id' must be a tweet id created after 2022-05-03T03:15Z. Please use a 'since_id' that is larger than 1521327559768276992"
[dev:remix]       }
[dev:remix]     ],
[dev:remix]     "title": "Invalid Request",
[dev:remix]     "detail": "One or more parameters to your request was invalid.",
[dev:remix]     "type": "https://api.twitter.com/2/problems/invalid-request"
[dev:remix]   },
[dev:remix]   "rateLimit": {
[dev:remix]     "limit": 450,
[dev:remix]     "remaining": 214,
[dev:remix]     "reset": 1652153179
[dev:remix]   },
[dev:remix]   "headers": {
[dev:remix]     "date": "Tue, 10 May 2022 03:15:39 UTC",
[dev:remix]     "server": "tsa_a",
[dev:remix]     "set-cookie": [
[dev:remix]       "guest_id_marketing=v1%3A165215253979181578; Max-Age=63072000; Expires=Thu, 09 May 2024 03:15:39 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None",
[dev:remix]       "guest_id_ads=v1%3A165215253979181578; Max-Age=63072000; Expires=Thu, 09 May 2024 03:15:39 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None",
[dev:remix]       "personalization_id=\"v1_W9B6Er6ZjSKV9sQJdFK97w==\"; Max-Age=63072000; Expires=Thu, 09 May 2024 03:15:39 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None",
[dev:remix]       "guest_id=v1%3A165215253979181578; Max-Age=63072000; Expires=Thu, 09 May 2024 03:15:39 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None"
[dev:remix]     ],
[dev:remix]     "api-version": "2.42",
[dev:remix]     "content-type": "application/json; charset=utf-8",
[dev:remix]     "cache-control": "no-cache, no-store, max-age=0",
[dev:remix]     "content-length": "273",
[dev:remix]     "x-access-level": "read",
[dev:remix]     "x-frame-options": "SAMEORIGIN",
[dev:remix]     "content-encoding": "gzip",
[dev:remix]     "x-xss-protection": "0",
[dev:remix]     "x-rate-limit-limit": "450",
[dev:remix]     "x-rate-limit-reset": "1652153179",
[dev:remix]     "content-disposition": "attachment; filename=json.json",
[dev:remix]     "x-content-type-options": "nosniff",
[dev:remix]     "x-rate-limit-remaining": "214",
[dev:remix]     "strict-transport-security": "max-age=631138519",
[dev:remix]     "x-response-time": "23",
[dev:remix]     "x-connection-hash": "4e6d6ae0ac27094a474aa5c46cdc75bfc585357535864b96c62662bf20678762",
[dev:remix]     "connection": "close"
[dev:remix]   }
[dev:remix] }
[dev:remix] PATCH /clusters/climate/tweets?_data=routes%2F%24src.%24id%2Ftweets 500 - - 4999.027 ms
nicholaschiang commented 2 years ago

To fix, I'm simply going to make that cache a setEx with a week old as it's expiry date.