访问 Twitter API 端点时出错:对 v1.1 和 v2 端点的访问受限

问题描述 投票:0回答:2

我正在尝试使用 JavaScript 中的

twit
库检索包含特定主题标签的推文。但是,我遇到了与对某些 Twitter API 端点的访问受限相关的错误。我收到的错误消息是:
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

这是我正在使用的代码:

const Twit = require('twit');

const XLSX = require('xlsx');

// Twitter API credentials (replace with your own)

const T = new Twit({

  consumer_key: 'YOUR_CONSUMER_KEY',

  consumer_secret: 'YOUR_CONSUMER_SECRET',

  access_token: 'YOUR_ACCESS_TOKEN',

  access_token_secret: 'YOUR_ACCESS_TOKEN_SECRET'

});

// Search parameters

const hashtag = '#Example';

const count = 100; // Number of tweets to retrieve

// Search tweets containing the hashtag

T.get('search/tweets', { q: hashtag, count }, (err, data) => {

  if (err) {

    console.error('Error:', err);

    return;

  }

  

  const tweetLinks = data.statuses.map(tweet => `https://twitter.com/${tweet.user.screen_name}/status/${tweet.id_str}`);

  

  // Create a new worksheet

  const ws = XLSX.utils.aoa_to_sheet([tweetLinks]);

  const wb = XLSX.utils.book_new();

  XLSX.utils.book_append_sheet(wb, ws, 'Tweet Links');

  

  // Save the Excel file

  XLSX.writeFile(wb, 'tweetLinks.xlsx');

  

  console.log('Excel file generated with tweet links.');

});


我相信该错误与我尝试访问的端点有关。如何解决此问题并访问必要的 Twitter API 端点以检索我需要的推文?任何指导或建议将不胜感激。

附加信息:

我正在使用 Node.js 中的 twit 库与 Twitter API 进行交互。

我检查了我的 Twitter API 凭据,它们似乎是正确的。

我专门尝试检索带有特定主题标签的推文:#Example。

通过提供清晰的标题、对问题的详细解释以及您正在使用的代码,您更有可能从 Stack Overflow 社区收到准确且有用的回复。

我现在很困惑该怎么做,我期待我的错误得到解决方案

javascript node.js twitter-oauth endpoint
2个回答
0
投票

请在此处跟进 Twitter API 文档 在此处输入链接描述

v1.1 已被弃用(已删除),如果 v2 中没有可用的替代 API,则在没有 Enterprise API 访问权限的情况下您无法真正访问它。

顺便说一句,企业 API 访问费用为每月 42000 美元,没有基于消费的模型。


0
投票

我也遇到同样的问题

{"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}

阅读完Twitter (X)文档后唯一的答案是使用BASIC和PRO级别访问来获取推文数据。

没有其他办法!

© www.soinside.com 2019 - 2024. All rights reserved.