Booyah平台粉丝采集自动关注脚本功能异常Bug修复求助
问题根因
- 核心错误:脚本在采集到粉丝列表后,调用关注接口时传入的是基准目标账号的UID,而非采集到的每一个粉丝UID,导致仅关注了基准账号
- 辅助问题:未等待关注接口请求完成就进入下一轮逻辑,可能出现请求丢失;未设置请求间隔容易触发平台风控拦截
修复后完整脚本
const csrf = '替换为你自己的CSRF_TOKEN'; async function booyahGetAccounts(uid, type = 'followers', follow = 1) { // 请求间隔(毫秒,避免触发限流,可根据实际情况调整) const REQUEST_DELAY = 1000; if (typeof uid !== 'undefined' && !isNaN(uid)) { const loggedInUserID = window.localStorage?.loggedUID; if (uid === 0) uid = loggedInUserID; const unfollow = follow === -1; if (unfollow) follow = 1; if (loggedInUserID) { if (csrf) { async function getUserData(uid) { const response = await fetch(`https://booyah.live/api/v3/users/${uid}`), data = await response.json(); return data.user; } const loggedInUserData = await getUserData(loggedInUserID), targetUserData = await getUserData(uid), followUser = async uid => { const res = await fetch(`https://booyah.live/api/v3/users/${loggedInUserID}/followings`, { method: (unfollow ? 'DELETE' : 'POST'), headers: { 'X-CSRF-Token': csrf }, body: JSON.stringify({ followee_uid: uid, source: 43 }) }); // 请求后等待固定间隔避免触发限流 await new Promise(resolve => setTimeout(resolve, REQUEST_DELAY)); return res; }, logSep = (data = '', usePad = 0) => typeof data === 'string' && usePad ? console.log((data ? data + ' ' : '').padEnd(50, '━')) : console.log('━'.repeat(50),data,'━'.repeat(50)); async function getList(uid, type, follow) { const isLoggedInUser = uid === loggedInUserID; if (isLoggedInUser && follow && !unfollow && type === 'followings') { follow = 0; console.warn('You alredy follow your followings. `follow` mode switched to `false`. Followings will be retrieved instead of followed.'); } const userData = await getUserData(uid), totalCount = userData[type.slice(0,-1)+'_count'] || 0, totalCountStrLength = totalCount.toString().length; if (totalCount) { let userIDsLength = 0; const userIDs = [], nickname = userData.nickname, nicknameStr = `${nickname ? ` of ${nickname}'s ${type}` : ''}`, alreadyFollowedStr = uid => `User ID ${uid} already followed by ${loggedInUserData.nickname} (Account #${loggedInUserID})`; async function followerFetch(cursor = 0) { const fetched = []; await fetch(`https://booyah.live/api/v3/users/${uid}/${type}?cursor=${cursor}&count=100`).then(res => res.json()).then(async data => { const list = data[type.slice(0,-1)+'_list']; if (list?.length) fetched.push(...list.map(e => e.uid)); if (fetched.length) { userIDs.push(...fetched); userIDsLength += fetched.length; // 修复点:遍历所有采集到的用户ID执行关注/取关操作 if (follow) { for (const targetUid of fetched) { await followUser(targetUid); } } console.log(`${userIDsLength.toString().padStart(totalCountStrLength)} (${(userIDsLength / totalCount * 100).toFixed(4)}%)${nicknameStr} ${follow ? 'followed' : 'retrieved'}`); if (fetched.length === 100) { followerFetch(data.cursor); } else { console.log(`END REACHED. ${userIDsLength} accounts ${follow ? 'followed' : 'retrieved'}.`); if (!follow) logSep(targetList); } } }); } await followerFetch(); return userIDs; } else { console.log(`This account has no ${type}.`); } } logSep(`${follow ? 'Following' : 'Retrieving'} ${targetUserData.nickname}'s ${type}`, 1); const targetList = await getList(uid, type, follow); } else { console.error('Missing CSRF token. Retrieve your CSRF token from the Network tab in your inspector by clicking into the Network tab item named "bug-report-claims" and then scrolling down in the associated details window to where you see "x-csrf-token". Copy its value and store it into a variable named "csrf" which this function will reference when you execute it.'); } } else { console.error('You do not appear to be logged in. Please log in and try again.'); } } else { console.error('UID not passed. Pass the UID of the profile you are targeting to this function.'); } }
使用说明
- 登录Booyah平台后,从浏览器开发者工具Network面板找到
bug-report-claims请求,复制请求头中的x-csrf-token值,替换脚本开头的替换为你自己的CSRF_TOKEN - 批量关注指定账号粉丝:调用
booyahGetAccounts(目标账号UID, 'followers', 1) - 批量取关自己已关注的账号:调用
booyahGetAccounts(0, 'followings', -1) - 仅采集账号列表不执行关注/取关:调用
booyahGetAccounts(目标账号UID, 'followers', 0)
内容的提问来源于stack exchange,提问作者Digital Farmer
相关产品推荐
相关产品推荐

