← back to Norma
auto-save: 2026-07-23T08:19:35 (2 files) — agents/instagram-agent/skills/discover.js agents/instagram-agent/skills/monitor.js
be528239ecb69f45450fbdd4dc4f3a1db5f67ae8 · 2026-07-23 08:19:43 -0700 · Steve Abrams
Files touched
M agents/instagram-agent/skills/discover.jsM agents/instagram-agent/skills/monitor.js
Diff
commit be528239ecb69f45450fbdd4dc4f3a1db5f67ae8
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Thu Jul 23 08:19:43 2026 -0700
auto-save: 2026-07-23T08:19:35 (2 files) — agents/instagram-agent/skills/discover.js agents/instagram-agent/skills/monitor.js
---
agents/instagram-agent/skills/discover.js | 97 +++++++++++++++----------------
agents/instagram-agent/skills/monitor.js | 78 ++++++++++++-------------
2 files changed, 87 insertions(+), 88 deletions(-)
diff --git a/agents/instagram-agent/skills/discover.js b/agents/instagram-agent/skills/discover.js
index 1064e40..5d8d18c 100644
--- a/agents/instagram-agent/skills/discover.js
+++ b/agents/instagram-agent/skills/discover.js
@@ -80,54 +80,53 @@ module.exports = async function discover(params) {
}
// --- Real API call (commented out until credentials are configured) ---
- //
- // const igUserId = process.env.IG_USER_ID;
- // const accessToken = process.env.IG_ACCESS_TOKEN;
- //
- // // Fetch recent media
- // const fields = 'id,caption,media_type,media_url,permalink,timestamp,like_count,comments_count';
- // const mediaUrl = `https://graph.facebook.com/v19.0/${igUserId}/media?fields=${fields}&limit=${limit}&access_token=${accessToken}`;
- //
- // const mediaResponse = await fetch(mediaUrl);
- // const mediaData = await mediaResponse.json();
- //
- // if (mediaData.error) {
- // throw new Error(`Instagram API error (media): ${mediaData.error.message}`);
- // }
- //
- // let hashtagResults = null;
- // if (hashtag) {
- // // Step 1: Get hashtag ID
- // const htSearchUrl = `https://graph.facebook.com/v19.0/ig_hashtag_search?q=${encodeURIComponent(hashtag)}&user_id=${igUserId}&access_token=${accessToken}`;
- // const htSearchResponse = await fetch(htSearchUrl);
- // const htSearchData = await htSearchResponse.json();
- //
- // if (htSearchData.data && htSearchData.data.length > 0) {
- // const hashtagId = htSearchData.data[0].id;
- //
- // // Step 2: Get recent media for hashtag
- // const htMediaUrl = `https://graph.facebook.com/v19.0/${hashtagId}/recent_media?user_id=${igUserId}&fields=id,caption,media_type,permalink,timestamp&access_token=${accessToken}`;
- // const htMediaResponse = await fetch(htMediaUrl);
- // const htMediaData = await htMediaResponse.json();
- //
- // hashtagResults = {
- // hashtag,
- // hashtag_id: hashtagId,
- // count: htMediaData.data?.length || 0,
- // results: htMediaData.data || [],
- // };
- // }
- // }
- //
- // return {
- // count: mediaData.data.length,
- // media: mediaData.data,
- // hashtag_search: hashtagResults,
- // paging: mediaData.paging || null,
- // simulated: false,
- // platform: PLATFORM,
- // fetched_at: new Date().toISOString(),
- // };
+
+ const igUserId = process.env.IG_USER_ID;
+ const accessToken = process.env.IG_ACCESS_TOKEN;
+
+ // Fetch recent media
+ const fields = 'id,caption,media_type,media_url,permalink,timestamp,like_count,comments_count';
+ const mediaUrl = `https://graph.facebook.com/v19.0/${igUserId}/media?fields=${fields}&limit=${limit}&access_token=${accessToken}`;
+
+ const mediaResponse = await fetch(mediaUrl);
+ const mediaData = await mediaResponse.json();
+
+ if (mediaData.error) {
+ throw new Error(`Instagram API error (media): ${mediaData.error.message}`);
+ }
+
+ let hashtagResults = null;
+ if (hashtag) {
+ // Step 1: Get hashtag ID
+ const htSearchUrl = `https://graph.facebook.com/v19.0/ig_hashtag_search?q=${encodeURIComponent(hashtag)}&user_id=${igUserId}&access_token=${accessToken}`;
+ const htSearchResponse = await fetch(htSearchUrl);
+ const htSearchData = await htSearchResponse.json();
+
+ if (htSearchData.data && htSearchData.data.length > 0) {
+ const hashtagId = htSearchData.data[0].id;
+
+ // Step 2: Get recent media for hashtag
+ const htMediaUrl = `https://graph.facebook.com/v19.0/${hashtagId}/recent_media?user_id=${igUserId}&fields=id,caption,media_type,permalink,timestamp&access_token=${accessToken}`;
+ const htMediaResponse = await fetch(htMediaUrl);
+ const htMediaData = await htMediaResponse.json();
+
+ hashtagResults = {
+ hashtag,
+ hashtag_id: hashtagId,
+ count: htMediaData.data?.length || 0,
+ results: htMediaData.data || [],
+ };
+ }
+ }
+
+ return {
+ count: mediaData.data.length,
+ media: mediaData.data,
+ hashtag_search: hashtagResults,
+ paging: mediaData.paging || null,
+ simulated: false,
+ platform: PLATFORM,
+ fetched_at: new Date().toISOString(),
+ };
- return { error: 'Real API call not yet enabled. Uncomment the code above.' };
};
diff --git a/agents/instagram-agent/skills/monitor.js b/agents/instagram-agent/skills/monitor.js
index 61e1bc0..c835a09 100644
--- a/agents/instagram-agent/skills/monitor.js
+++ b/agents/instagram-agent/skills/monitor.js
@@ -61,44 +61,44 @@ module.exports = async function monitor(params) {
}
// --- Real API call (commented out until credentials are configured) ---
- //
- // const igUserId = process.env.IG_USER_ID;
- // const accessToken = process.env.IG_ACCESS_TOKEN;
- //
- // // Fetch insights
- // const metrics = 'reach,impressions,follower_count,profile_views,website_clicks,email_contacts';
- // const insightsUrl = `https://graph.facebook.com/v19.0/${igUserId}/insights?metric=${metrics}&period=${period}&access_token=${accessToken}`;
- //
- // const insightsResponse = await fetch(insightsUrl);
- // const insightsData = await insightsResponse.json();
- //
- // if (insightsData.error) {
- // throw new Error(`Instagram API error (insights): ${insightsData.error.message}`);
- // }
- //
- // const insights = {};
- // for (const entry of insightsData.data) {
- // const value = entry.values?.[entry.values.length - 1]?.value || 0;
- // insights[entry.name] = value;
- // }
- //
- // // Fetch account info
- // const accountUrl = `https://graph.facebook.com/v19.0/${igUserId}?fields=followers_count,follows_count,media_count&access_token=${accessToken}`;
- // const accountResponse = await fetch(accountUrl);
- // const accountData = await accountResponse.json();
- //
- // return {
- // insights,
- // account: {
- // followers_count: accountData.followers_count,
- // follows_count: accountData.follows_count,
- // media_count: accountData.media_count,
- // },
- // period,
- // simulated: false,
- // platform: PLATFORM,
- // checked_at: new Date().toISOString(),
- // };
+
+ const igUserId = process.env.IG_USER_ID;
+ const accessToken = process.env.IG_ACCESS_TOKEN;
+
+ // Fetch insights
+ // valid metric set per Graph v21+ (impressions/email_contacts deprecated)
+ const metrics = 'reach,follower_count,profile_views,website_clicks';
+ const insightsUrl = `https://graph.facebook.com/v19.0/${igUserId}/insights?metric=${metrics}&period=${period}&access_token=${accessToken}`;
+
+ const insightsResponse = await fetch(insightsUrl);
+ const insightsData = await insightsResponse.json();
+
+ if (insightsData.error) {
+ throw new Error(`Instagram API error (insights): ${insightsData.error.message}`);
+ }
+
+ const insights = {};
+ for (const entry of insightsData.data) {
+ const value = entry.values?.[entry.values.length - 1]?.value || 0;
+ insights[entry.name] = value;
+ }
+
+ // Fetch account info
+ const accountUrl = `https://graph.facebook.com/v19.0/${igUserId}?fields=followers_count,follows_count,media_count&access_token=${accessToken}`;
+ const accountResponse = await fetch(accountUrl);
+ const accountData = await accountResponse.json();
+
+ return {
+ insights,
+ account: {
+ followers_count: accountData.followers_count,
+ follows_count: accountData.follows_count,
+ media_count: accountData.media_count,
+ },
+ period,
+ simulated: false,
+ platform: PLATFORM,
+ checked_at: new Date().toISOString(),
+ };
- return { error: 'Real API call not yet enabled. Uncomment the code above.' };
};
← e6864e6 auto-save: 2026-07-23T07:19:17 (1 files) — scripts/gmail-bac
·
back to Norma
·
instagram-agent fully LIVE: real token installed, monitor/di b9d1c04 →