如何从推文的评论部分获取钱包地址
#javascript #教程 #twitter #web3

如果您想在Twitter上执行Airdrop或营销活动,但是想知道您将如何从评论中获取所有钱包地址,这是一种快速简便的方法!

注册以获取Twitter开发访问(https://developer.twitter.com/en/portal/dashboard),一旦完成

创建一个项目
Image description

并获得您的承载令牌

Image description

现在到代码!

要求
节点JS 16及以上
Axios

import fs from "fs"; 
import axios from "axios";
var resultsNext_token = "";
var count = 0;
var arrayWallets = [] //Array of wallets
var regexPattern = /[^A-Za-z0-9]/g //Removes Pesky emojis and non alphanumerical text; 

async function runthis(id){
while (count < 13) { //Count is num *100(100 comments per request) so this goes through 1,300 comments
  const response = await axios.get(
    `https://api.twitter.com/2/tweets/search/recent?query=conversation_id:${id}&max_results=100&tweet.fields=in_reply_to_user_id,author_id,created_at,conversation_id&${
      resultsNext_token ? `next_token=${resultsNext_token}` : ""
    }`,
    {
      headers: {
        Authorization: `Bearer ${BEARER}`,
      },
    }
  );
  const resultsArray = response.data.data;
  resultsNext_token = response.data.meta.next_token;
  if (resultsArray != undefined) {
    resultsArray.map(data=>{
      const datatext = data.text.replaceAll("\n"," ").split(" ")
      datatext.map((data)=>{
        if(data.length>30){ // Checks for long strings(possibily wallets)
          arrayWallets .push(data.replace(regexPattern, ""))
        }
    })
    })
    // arrayWallets  = [...arrayWallets ,...resultsArray]

    count = count + 1;
    if(count ==13){ // after 1300 comments searched
      let data = JSON.stringify(arrayWallets );

fs.writeFileSync("walletArrayOut.json", data); // stores wallets in a json file as an array
    }
  } else {
    return false;
  }
}

您有它,希望它有帮助!