我想知道如何检索用户在 Instagram 上关注的人员列表。假设这个特定用户是我关注的人。所以我可以在 Instagram 应用程序上访问他/她的照片和他的关注者。
如何使用 Instagram API 来执行此操作?这样做合法吗?
进一步开发版本https://stackoverflow.com/a/63056537/11865501
- 在浏览器上打开 Instagram;
- 登录 Instagram;
- Open your browser's console (CTRL + SHIFT + J);
- 粘贴下面的代码;
- 更新第一行的用户名;
- RUN IT (Hit Enter)
const username = "USER_NAME_HERE";
/**
* Initialized like this so we can still run it from browsers, but also use typescript on a code editor for intellisense.
*/
let followers = [{ username: "", full_name: "" }];
let followings = [{ username: "", full_name: "" }];
let dontFollowMeBack = [{ username: "", full_name: "" }];
let iDontFollowBack = [{ username: "", full_name: "" }];
followers = [];
followings = [];
dontFollowMeBack = [];
iDontFollowBack = [];
(async () => {
try {
console.log(`Process started! Give it a couple of seconds`);
const userQueryRes = await fetch(
`https://www.instagram.com/web/search/topsearch/?query=${username}`
);
const userQueryJson = await userQueryRes.json();
const userId = userQueryJson.users[0].user.pk;
let after = null;
let has_next = true;
while (has_next) {
await fetch(
`https://www.instagram.com/graphql/query/?query_hash=c76146de99bb02f6415203be841dd25a&variables=` +
encodeURIComponent(
JSON.stringify({
id: userId,
include_reel: true,
fetch_mutual: true,
first: 50,
after: after,
})
)
)
.then((res) => res.json())
.then((res) => {
has_next = res.data.user.edge_followed_by.page_info.has_next_page;
after = res.data.user.edge_followed_by.page_info.end_cursor;
followers = followers.concat(
res.data.user.edge_followed_by.edges.map(({ node }) => {
return {
username: node.username,
full_name: node.full_name,
};
})
);
});
}
console.log({ followers });
after = null;
has_next = true;
while (has_next) {
await fetch(
`https://www.instagram.com/graphql/query/?query_hash=d04b0a864b4b54837c0d870b0e77e076&variables=` +
encodeURIComponent(
JSON.stringify({
id: userId,
include_reel: true,
fetch_mutual: true,
first: 50,
after: after,
})
)
)
.then((res) => res.json())
.then((res) => {
has_next = res.data.user.edge_follow.page_info.has_next_page;
after = res.data.user.edge_follow.page_info.end_cursor;
followings = followings.concat(
res.data.user.edge_follow.edges.map(({ node }) => {
return {
username: node.username,
full_name: node.full_name,
};
})
);
});
}
console.log({ followings });
dontFollowMeBack = followings.filter((following) => {
return !followers.find(
(follower) => follower.username === following.username
);
});
console.log({ dontFollowMeBack });
iDontFollowBack = followers.filter((follower) => {
return !followings.find(
(following) => following.username === follower.username
);
});
console.log({ iDontFollowBack });
console.log(
`Process is done: Type 'copy(followers)' or 'copy(followings)' or 'copy(dontFollowMeBack)' or 'copy(iDontFollowBack)' in the console and paste it into a text editor to take a look at it'`
);
} catch (err) {
console.log({ err });
}
})();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)