发布到 Twitter 失败:错误:您当前可以访问 Twitter API v2 端点的子集和有限的 v1.1 端点(例如媒体帖子、oauth)...

jth*_*ter 5 javascript twitter npm

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

\n

我的授权有效。当我运行时twitClient.get('account/verify_credentials', {\xe2\x80\xa6}),我会收到所有帐户详细信息。

\n

但有些东西阻止我的代码发推文。当我运行时twitClient.post('statuses/update', {\xe2\x80\xa6}, function (error, success) {}),我收到:

\n
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\n    at exports.makeTwitError (/Users/\xe2\x80\xa6/node_modules/twit/lib/helpers.js:74:13)\n    at onRequestComplete (/Users/\xe2\x80\xa6/node_modules/twit/lib/twitter.js:344:25)\n    at Request.<anonymous> (/Users/\xe2\x80\xa6/node_modules/twit/lib/twitter.js:364:7)\n    at Request.emit (node:events:523:35)\n    at Gunzip.<anonymous> (/Users/\xe2\x80\xa6/node_modules/request/request.js:1076:12)\n    at Object.onceWrapper (node:events:625:28)\n    at Gunzip.emit (node:events:511:28)\n    at endReadableNT (node:internal/streams/readable:1367:12)\n    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {\n  code: 453,\n  allErrors: [\n    {\n      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',\n      code: 453\n    }\n  ],\n  twitterReply: { errors: [ [Object] ] },\n  statusCode: 403\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我\xe2\x80\x99已经尝试将 Twit 换成 Twitter API V2 [https://www.npmjs.com/package/twitter-api-v2] 等更新的东西,但发推文的语法完全不同。

\n

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

\n

Tow*_*bib 0

POST /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 端点,那么这套指南适合您。”