File size: 3,257 Bytes
7e9ddb1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const axios = require('axios');

async function igstalk(user) {
  try {
    const profileResponse = await axios.post(
      'https://api.boostfluence.com/api/instagram-profile-v2',
      { username: user },
      { headers: { 'Content-Type': 'application/json' } }
    );

    const profile = profileResponse.data;

    let postsData = null;
    try {
      const initialPostsResponse = await axios.post(
        'https://api.boostfluence.com/api/instagram-viewer-v2-2',
        { username: user, type: 'photo', pagination_token: null },
        { headers: { 'Content-Type': 'application/json' } }
      );

      if (initialPostsResponse.data.error === 'COMPUTE_REQUIRED') {
        const { timestamp, expectedCompute } = initialPostsResponse.data.challenge;

        const verifiedPostsResponse = await axios.post(
          'https://api.boostfluence.com/api/instagram-viewer-v2-2',
          { username: user, type: 'photo', pagination_token: null },
          {
            headers: {
              'Content-Type': 'application/json',
              'X-Compute': expectedCompute.toString(),
              'X-Timestamp': timestamp.toString()
            }
          }
        );

        postsData = verifiedPostsResponse.data;
      } else {
        postsData = initialPostsResponse.data;
      }
    } catch (postsError) {
      console.error('Error fetching posts:', postsError.message);
    }

    return {
      profile: {
        username: profile.username,
        full_name: profile.full_name,
        biography: profile.biography,
        follower_count: profile.follower_count,
        following_count: profile.following_count,
        media_count: profile.media_count,
        profile_pic_url: profile.profile_pic_url,
        profile_pic_url_hd: profile.profile_pic_url_hd,
        is_verified: profile.is_verified,
        is_private: profile.is_private,
        external_url: profile.external_url,
        category: profile.category
      }
    };
  } catch (error) {
    throw new Error(`Failed to fetch Instagram data: ${error.message}`);
  }
}

const handler = async (req, res) => {
    try {
        const { username } = req.query;

        if (!username) {
            return res.status(400).json({
                success: false,
                error: 'Missing required parameter: username'
            });
        }

        const usernameRegex = /^[a-zA-Z0-9._]{1,30}$/;
        if (!usernameRegex.test(username)) {
            return res.status(400).json({
                success: false,
                error: 'Invalid username format'
            });
        }

        const result = await igstalk(username);

        res.json({
            author: "Herza",
            success: true,
            data: result
        });

    } catch (error) {
        res.status(500).json({
            author: "Herza",
            success: false,
            error: error.message
        });
    }
};

module.exports = {
    name: 'Instagram Stalk',
    description: 'Get Instagram user profile information including stats, bio, and posts',
    type: 'GET',
    routes: ['api/stalk/instagram'],
    tags: ['social', 'instagram', 'stalk', 'profile'],
    parameters: ['username', 'key'],
    enabled: true,
    main: ['Stalk'],
    handler
};