发布到Twitter失败:错误:您当前只能访问Twitter API v2的一部分端点和有限的v1.1端点(例如媒体发布、oauth)...

5

我有一个使用NPM Twit [https://www.npmjs.com/package/twit] 的JavaScript应用程序来发布推文到Twitter。我的机器人最近突然停止工作,没有任何解释或警告。Twitter似乎要求我从他们的旧免费套餐升级到他们的新免费套餐,这要求我删除我的Twitter开发帐户中的所有内容,然后重新创建我的项目和应用程序。我已经这样做了,并确保选择了读取和写入权限。

我的授权是有效的。当我运行twitClient.get('account/verify_credentials', {…})时,我可以收到所有帐户详细信息。

但是有些东西阻止了我的代码发布推文。当我运行twitClient.post('statuses/update', {…}, function (error, success) {})时,我收到以下消息:

Post to Twitter failure: Error: You currently have access to a subset of Twitter API v2 endpoints and limited v1.1 endpoints (e.g. media post, oauth) only. If you need access to this endpoint, you may need a different access level. You can learn more here: https://developer.twitter.com/en/portal/product
    at exports.makeTwitError (/Users/…/node_modules/twit/lib/helpers.js:74:13)
    at onRequestComplete (/Users/…/node_modules/twit/lib/twitter.js:344:25)
    at Request.<anonymous> (/Users/…/node_modules/twit/lib/twitter.js:364:7)
    at Request.emit (node:events:523:35)
    at Gunzip.<anonymous> (/Users/…/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (node:events:625:28)
    at Gunzip.emit (node:events:511:28)
    at endReadableNT (node:internal/streams/readable:1367:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 453,
  allErrors: [
    {
      message: 'You currently have access to a subset of Twitter API v2 endpoints and limited v1.1 endpoints (e.g. media post, oauth) only. If you need access to this endpoint, you may need a different access level. You can learn more here: https://developer.twitter.com/en/portal/product',
      code: 453
    }
  ],
  twitterReply: { errors: [ [Object] ] },
  statusCode: 403
}

我尝试将Twit更换为一些更新的东西,比如Twitter API V2[https://www.npmjs.com/package/twitter-api-v2],但是发推文的语法完全不同。

我尝试搜索答案,但我只找到了Python代码。


你需要使用V2 API进行推文,因为V1.1已经不再可用。 - Markus Kauppinen
你需要使用V2 API进行推特,因为V1.1已经不可用。 - undefined
1个回答

0

目前,/2/tweets接口属于免费计划,所以你应该可以在v2版本中发布推文而无需升级。

请查看此文档,https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/migrate,因为你已经找到了一些代码,所以我就不再包含在内了。

根据文档,为了让你更清楚明白,

"v2版本的管理推文接口将取代标准的v1.1版本的POST statuses/update和POST statuses/destroy/:id接口。如果你有使用v1.1版本的管理推文接口的代码、应用程序或工具,并且正在考虑迁移到更新的Twitter API v2接口,那么这一系列指南就是为你准备的。"


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接