Ice9Coffee / HoshinoBot

A qqbot for Princess Connect Re:Dive (and other usage :)
GNU General Public License v3.0
1.41k stars 411 forks source link

twitter 推送需要使用 v2 #269

Closed clacknya closed 1 year ago

clacknya commented 1 year ago
[2023-03-15 15:00:43,937 twitter-poller] INFO: Got twitter event.

Traceback (most recent call last):
  File "/home/HoshinoBot/.local/lib/python3.9/site-packages/peony/stream.py", line 156, in __anext__
    return await self.restart_stream()
  File "/home/HoshinoBot/.local/lib/python3.9/site-packages/peony/stream.py", line 263, in restart_stream
    await self.connect()
  File "/home/HoshinoBot/.local/lib/python3.9/site-packages/peony/stream.py", line 126, in connect
    raise await exceptions.throw(self.response,
  File "/home/HoshinoBot/.local/lib/python3.9/site-packages/peony/exceptions.py", line 35, in throw
    raise exception(response=response, data=data, **kwargs)
peony.exceptions.HTTPForbidden: <html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>\n<title>Error 403
Please use V2 filtered and sample volume stream as alternatives
</title>
</head>
<body>
<h2>HTTP ERROR: 403</h2>
<p>Problem accessing '/1.1/statuses/filter.json'. Reason:
<pre>
Please use V2 filtered and sample volume stream as alternatives
</pre>
</body>
</html>
Ice9Coffee commented 1 year ago

271 #273 已添加适用于v2版api的转推插件(目前仅支持follow,暂不支持关键词track

Ice9Coffee commented 1 year ago

据说streaming api在一个月后将需要 Enterprise API 才可使用(42000美元/月)

clacknya commented 1 year ago

据说streaming api在一个月后将需要 Enterprise API 才可使用(42000美元/月)

前面看了下 v2 的 API,发现 stream 的设计有点反人类,限制请求字符串的长度,要是用户名长点的就加不了多少了😂就自己改成 get_users_tweets 轮询了,限制请求频率。目前运行还算稳定。

clacknya commented 1 year ago

目前公布的 free 计划似乎只能发推?

Ice9Coffee commented 1 year ago

轮询也有次数限制,即时性会受到影响(订阅越多延迟越大) 现在的stream大约可以订阅100个

clacknya commented 1 year ago

轮询也有次数限制,即时性会受到影响(订阅越多延迟越大) 现在的stream大约可以订阅100个

其实还行,目前订阅50左右,基本发出5s内就能收到推送。设置个已经获取过 tweet_id 的缓存集合,不时一轮查询完,第二轮查询时还能命中已经获取过的 tweet 而忽略。

按文档说的频率限制就每次查询间隔1s,还算可以接受。