我有一个运行 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代码。
POST /2/tweets 目前属于免费计划,因此您应该能够在不升级 v2 的情况下发布推文。 检查此文档,https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/migrate,因为您已经找到了一些代码,所以我不包括它。
从文档中,为了让您更清楚,
” v2 管理推文端点将取代标准 v1.1 POST 状态/更新和 POST 状态/销毁/:id 端点。如果您有使用 v1.1 版本管理推文端点的代码、应用程序或工具,并且正在考虑迁移到较新的 Twitter API v2 端点,那么这套指南适合您。“