M README.md => README.md +2 -2
@@ 1,5 1,5 @@
-# Get Instagram Picture
-> Get user pictures of Instagram without token or whatever
+# Get Instagram Feed
+> Get user's feed of Instagram without token or whatever
*IMPORTANT: Unable to retrieve images from private accounts.*
M now.json => now.json +2 -2
@@ 1,7 1,7 @@
{
- "name": "get-instagram-picture",
+ "name": "get-instagram-feed",
"version": 2,
- "alias": ["get-instagram-picture.now.sh"],
+ "alias": ["get-instagram-feed.now.sh"],
"env": {
"NODE_ENV": "production"
},
M package-lock.json => package-lock.json +7 -2
@@ 1,6 1,6 @@
{
- "name": "get-instagram-picture",
- "version": "0.1.1",
+ "name": "get-instagram-feed",
+ "version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ 13,6 13,11 @@
"@types/node": "*"
}
},
+ "@romuloalves/get-instagram-data": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/@romuloalves/get-instagram-data/-/get-instagram-data-1.0.0.tgz",
+ "integrity": "sha512-3qUmGc/eVRwqMB8YenD75o+wdeB2UOG4tAp9yvQ/ueL4XxbUbJ2ZPHa3Ne8QCUlpz7IMRktw9LJVwZysm2yTwA=="
+ },
"@types/node": {
"version": "12.7.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.1.tgz",
M package.json => package.json +3 -2
@@ 1,6 1,6 @@
{
- "name": "get-instagram-picture",
- "version": "0.1.1",
+ "name": "get-instagram-feed",
+ "version": "1.0.0",
"scripts": {
"start": "micro",
"dev": "micro-dev"
@@ 13,6 13,7 @@
"micro-dev": "3.0.0"
},
"dependencies": {
+ "@romuloalves/get-instagram-data": "^1.0.0",
"micro": "9.3.4"
},
"license": "MIT"
M src/get-picture.ts => src/get-picture.ts +3 -26
@@ 1,16 1,4 @@
-import { get } from 'https';
-
-const startDataString = 'window._sharedData = ';
-const getInstagramUrl = (id: string) => `https://www.instagram.com/${id}/`;
-
-const getJsonData = (html:string): Object => {
- const startIndex = html.indexOf(startDataString) + startDataString.length
- const endIndex = html.indexOf(';</script>', startIndex)
- const substring = html.substring(startIndex, endIndex)
- const data = JSON.parse(substring)
-
- return getImages(data)
-};
+import getInstagramData from '@romuloalves/get-instagram-data';
const getImages = (data: any): Array<Object> => {
if (data == null || data.entry_data == null ||
@@ 48,18 36,7 @@ const getImages = (data: any): Array<Object> => {
}
export default async user => {
- return new Promise((resolve, reject) => {
- const userUrl = getInstagramUrl(user);
- let html = '';
-
- get(userUrl, res => {
- res.on('data', chunk => {
- html += chunk;
- });
+ const data = await getInstagramData(user);
- res.on('end', () => {
- resolve(getJsonData(html));
- });
- }).on('error', err => reject(err));
- });
+ return getImages(data);
};