我正在使用twitter-api-v2包,我无法保存我的access_token
,access_token_secret
和oauth_verifier
。我想保存oauth_verifier
,因为我想在另一个文件中创建实际的bot。
这是我发现的
- 使用writeFile会在catch语句中抛出错误
- 使用writeFileSync使我停留在页面上,并且不写入文件
- 尝试推文一些工作,推文是在后台发送的,但我停留在页面
client
.login(oauth_verifier)
.then(({ client: loggedClient, accessToken, accessSecret }) => {
let tokens = {
accessToken: accessToken,
accessSecret: accessSecret,
};
fs.writeFile("./tokens.json", JSON.stringify(tokens));
// loggedClient.v2.tweet("hello this is test number: 3"); << this works. i stay stuck
//on the redirect page, but the tweet is sent
})
.catch(() => res.status(403).send("Invalid verifier or access tokens!"));
我能够保存我的access_token
和access_token_secret
我第一次运行这段代码。但我再也不能了。
我还将补充,以清除任何混乱,我不是提供服务。这是一个机器人,我正在创建实践,我不提供服务。
我的问题已经解决。事实证明,问题是我没有向twitter发送成功的回复。我只需要在我的.then()
中发送一个200状态响应,在那里我写我的json文件。