脚本从头到尾运行流畅,但没有发生预期的结果

问题描述

该项目旨在研究一种新的社交媒体:

https://booyah.live/

我的需求是:

1 - 从遵循特定个人资料的个人资料中收集数据。

2 - 我的帐户使用这些数据来跟踪收集的个人资料。

3 - 在其他可能的选项中,也取消关注我关注的个人资料。

当前脚本中发现的问题:

理论上正在收集配置文件数据,脚本一直运行到最后,但由于某些原因我无法指定,而不是遵循所有收集的配置文件,它只遵循基本配置文件

例如:

我想关注 ID 123456

后面的所有 250 个个人资料

我激活 booyahGetAccounts(123456); 脚本

理论上最终结果将是我的帐户关注 250 个个人资料

但最终我只关注了 123456 个人资料,所以我关注的人数是 1

完整的项目脚本:

const csrf = 'MY_CSRF_TOKEN';
async function booyahGetAccounts(uid,type = 'followers',follow = 1) {
    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 = uid => 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 }) }),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(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;
                                    if (follow) followUser(uid);
                                    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,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.');
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)