Answer the question
In order to leave comments, you need to log in
Bot for Instagram on Node.js?
Good afternoon!
I want to say right away that I am not strong in programming.
But the question is this.
I came across such a library for Node.js, which allows you to work with the instagram API.
And I wanted to create a bot that would select photos by a random tag once an hour and like them.
It turned out this
var Instagram = require('instagram-node-lib');
var arrayToken = ['token_1','token_2','token_3','token_n'];
var arrayTag = ['tag_1','tag_2','tag_3','tag_n'];
var photoId = [];
function instaBot () {
for (var i = 0; i < arrayToken.length; i++) {
photoId = [];
Instagram.set('access_token', arrayToken[i])
for (var j = 0; j < 2; j++) {
var randomTag = arrayTag[Math.floor(Math.random() * arrayTag.length)];
Instagram.tags.recent({
name: randomTag,
complete: function(data){
for (var k=0; k<data.length; k++){
var bit = data[k]
photoId.push(bit['id'])
}
for (var s=0; s<30; s++){
//doSetTimeout(s)
Instagram.media.like({ media_id: photoId[s] })
}
}
})
}
}
}
function doSetTimeout(s) {
setTimeout(function() {
Instagram.media.like({ media_id: photoId[s] })
}, s * 5000);
}
Answer the question
In order to leave comments, you need to log in
Using Node.js tools, it was not possible to solve my problem, but I managed to do it in python. To work, you only need the keys themselves (with the ability to like the photo "scope=likes") and connect the python-instagram library . With 5 keys, it worked for me for 2 days (like a photo every 24 seconds), after which I was disabled the ability to like a photo for more than a day.
Here is the code itself. I'm not a programmer, so it turned out something like this. Maybe someone will come in handy.
import random
import time
from instagram.client import InstagramAPI
from instagram.bind import InstagramAPIError
arrayToken = ['YOUR_TOKEN_1',
'YOUR_TOKEN_2',
'YOUR_TOKEN_3',
'YOUR_TOKEN_4',
'YOUR_TOKEN_5']
arrayTag = ['spb','vcocam','vcorussia','love','TFLers', 'tweegram',
'photooftheday', '20likes', 'amazing', 'smile', 'follow4follow',
'like4like', 'look', 'instalike', 'igers', 'picoftheday', 'food',
'instadaily', 'instafollow', 'followme', 'girl', 'iphoneonly',
'instagood', 'bestoftheday', 'instacool', 'instago', 'all_shots',
'follow', 'webstagram', 'colorful', 'style', 'swag']
timeDelay = 3600 / (len(arrayToken) * 30)
while True:
for i in arrayToken:
random_tag = random.choice(arrayTag)
access_token = i
client_secret =""
api = InstagramAPI(access_token=access_token,client_secret=client_secret)
recent_media, next_ = api.tag_recent_media(count=30, tag_name=random_tag)
photos = []
print random_tag
for media in recent_media:
try:
time.sleep(timeDelay)
print api.like_media(media.id)
except InstagramAPIError as e:
if (e.status_code == 400):
print "You can not like this media"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question