Twitter Followers

FREEMIUM
By CrystalCrumble | Updated il y a 21 jours | Data
Popularity

0.4 / 10

Latency

127,263ms

Service Level

0%

Health Check

N/A

Back to All Tutorials (2)

How to get all followings from a profile?

const axios = require("axios");
const sleep = require("util").promisify(setTimeout);

// API Key from RapidAPI
const API_KEY = "your key";
// Twitter account username
const TWITTER_USERNAME = "DropTvshow";
// To avoid hitting the rate limit (in milliseconds)
const COOLDOWN = 1000;

async function getFollowing() {
	let page = 1;
	let following = [];

	while (true) {
		const { data } = await axios.get(
			`https://twitter-followers.p.rapidapi.com/${TWITTER_USERNAME}/following?page=${page}`,
			{
				headers: {
					"x-rapidapi-host": "twitter-followers.p.rapidapi.com",
					"x-rapidapi-key": API_KEY,
				},
			}
		);

		if (data.following.length === 0) break;

		following = [...following, ...data.following];

		page++;
		await sleep(COOLDOWN);
	}

	return following;
}

getFollowing()
	.then((following) => {
		console.log(following);
	})
	.catch((e) => {
		console.log(e);
	});