Socket
Socket
Sign inDemoInstall

instagram-fetcher

Package Overview
Dependencies
115
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.1.0

.env

91

lib/fetcher.js

@@ -0,5 +1,96 @@

require('dotenv').config();
const axios = require('axios');
const { JSDOM } = require('jsdom');
const BASE_URL_IG = 'https://graph.facebook.com/v16.0/';
class InstaFetcherPro {
constructor() {
this.accessToken = process.env.ACCESS_TOKEN;
}
async fetchData() {
const accessToken = this.accessToken;
const igAccount = await this.getAccounts(accessToken);
if (!igAccount) console.log('!igAccount');
const igAccountId = igAccount.id;
const allPosts = await this.getAllPosts(accessToken, igAccountId);
if (!allPosts) console.log('!allPosts');
for (const post of allPosts) {
const postData = await this.getPostData(accessToken, post);
if (!postData) console.log('!postData');
if (postData.media_type === 'IMAGE' || postData.media_type === 'VIDEO') {
this.storeImageVideo(postData, igAccountId);
} else if (postData.media_type === 'CAROUSEL_ALBUM') {
await this.storeCarouselItems(accessToken, postData, igAccountId);
}
}
}
async getAccounts(accessToken) {
try {
const response = await axios.get(`${BASE_URL_IG}me/accounts?access_token=${accessToken}`);
if (response.data.data.length > 0) {
return response.data.data[0];
}
console.log(`No Instagram accounts found for access token ${accessToken}`);
return null;
} catch (error) {
console.log(`Error fetching Instagram accounts for access token ${accessToken}: ${error.message}`);
return null;
}
}
async getAllPosts(accessToken, igAccountId) {
try {
const response = await axios.get(`${BASE_URL_IG}${igAccountId}/media?access_token=${accessToken}`);
if (response.data.data.length > 0) {
return response.data.data;
}
console.log(`No Instagram posts found for access token ${accessToken}`);
return null;
} catch (error) {
console.log(`Error fetching Instagram posts for access token ${accessToken}: ${error.message}`);
return null;
}
}
async getPostData(accessToken, post) {
try {
const response = await axios.get(`${BASE_URL_IG}${post.id}?fields=id,caption,media_type,media_url,thumbnail_url,permalink,timestamp&access_token=${accessToken}`);
if (response.data) {
return response.data;
}
console.log(`No Instagram post data found for access token ${accessToken} and post ID ${post.id}`);
return null;
} catch (error) {
console.log(`Error fetching Instagram post data for access token ${accessToken} and post ID ${post.id}: ${error.message}`);
return null;
}
}
async storeImageVideo(postData, igAccountId) {
// implementation here
}
async storeCarouselItems(accessToken, postData, igAccountId) {
// implementation here
}
async getPostsByUsername(username) {

@@ -6,0 +97,0 @@ try {

2

package.json
{
"name": "instagram-fetcher",
"version": "1.0.1",
"version": "1.1.0",
"description": "Fetch Instagram Business and Creator account feeds with this Node.js package. This package uses the Instagram Graph API to fetch all posts from an authorized Instagram Business or Creator account, including non-public posts.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,12 +5,20 @@ const InstaFetcherPro = require('./lib/fetcher');

const fetcher = new InstaFetcherPro();
const posts = await fetcher.getPostsByUsername('instagram');
const posts = await fetcher.fetchData('instagram');
console.log(posts)
return posts
// const posts = await fetcher.getPostsByUsername('instagram');
for (const post of posts) {
console.log(`ID: ${post.id}`);
console.log(`Type: ${post.type}`);
console.log(`Media URL(s): ${post.mediaUrl}`);
console.log(`Caption: ${post.caption}`);
console.log(`Timestamp: ${post.timestamp}`);
console.log('-------------------------');
}
// for (const post of posts) {
// console.log(`ID: ${post.id}`);
// console.log(`Type: ${post.type}`);
// console.log(`Media URL(s): ${post.mediaUrl}`);
// console.log(`Caption: ${post.caption}`);
// console.log(`Timestamp: ${post.timestamp}`);
// console.log('-------------------------');
// }
})();
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc