试图保存凭据时,卡在Twitter重定向页面上

发布于 2025-01-29 04:33:43 字数 1084 浏览 3 评论 0原文

我正在使用Twitter-API-V2软件包,我无法保存我的access_tokenaccess_token_secretoauth_verifier。我想保存oauth_verifier,因为我想在另一个文件中创建实际机器人。

这是我发现使用writefile的内容,

  • 捕获语句中给我带来了错误
  • 使用writefilesync的
  • 在 背景,但是i 在页面上保持卡住
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_tokenaccess_token_secret我第一次运行此代码。但是我不能了。

我还将补充说,为了清除任何混乱,我没有提供服务。这是我要练习的机器人,我没有提供服务。如果那是相关的。

I'm using the twitter-api-v2 package and I cant save my access_token, access_token_secret and oauth_verifier. i want to save the oauth_verifier because i want to create the actual bot in another file.

Here's what I've found

  • Using writeFile throws me the error in my catch statement
  • Using writeFileSync keeps me stuck on the page, and does not write to the file
  • Trying to tweet something works, the tweet is sent in the background, but i stay stuck on the page
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!"));

I was able to save my access_token and access_token_secret the first time i ran this code. but I cannot anymore.

I will also add, to clear any confusion, i am not providing a service. This is a bot that i am creating to practice, and i am not providing a servce. if that is relevant.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奢望 2025-02-05 04:33:43

我的问题已经解决。
事实证明,问题是我没有向Twitter发送成功回应。
我只需要在我的中发送200个状态响应。

my issue has been resolved.
Turns out, the problem was that i was not sending a success response to twitter.
I just needed to send a 200 status response in my .then() where i write to my json file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文