instagram-fetcher
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -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 { |
{ | ||
"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", |
26
test.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('-------------------------'); | ||
// } | ||
})(); |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
8555
151
0
3