# -*- coding: utf-8 -*-
#
# Use text editor to edit the script and type in valid Instagram username/password

import subprocess

from PyInstagramAPI import PyInstagramAPI

USERNAME = ''
PASSWORD = ''
FILE_PATH = '/path/to/video/file'
PUBLISH_TO_LIVE_FEED = False
SEND_NOTIFICATIONS = False

api = PyInstagramAPI(USERNAME, PASSWORD, debug=False)
assert api.login()

# first you have to create a broadcast - you will receive a broadcast id and an upload url here
assert api.createBroadcast()
broadcast_id = api.LastJson['broadcast_id']
upload_url = api.LastJson['upload_url']

# we now start a boradcast - it will now appear in the live-feed of users
assert api.startBroadcast(broadcast_id, sendNotification=SEND_NOTIFICATIONS)

ffmpeg_cmd = "ffmpeg -rtbufsize 256M -re -i '{file}' -acodec libmp3lame -ar 44100 -b:a 128k -pix_fmt yuv420p -profile:v baseline -s 720x1280 -bufsize 6000k -vb 400k -maxrate 1500k -deinterlace -vcodec libx264 -preset veryfast -g 30 -r 30 -f flv '{stream_url}'".format(
    file=FILE_PATH,
    stream_url=upload_url.replace(
        ':443',
        ':80',
    ).replace('rtmps://', 'rtmp://'),
import os
import time
import random
from os import listdir
from os.path import isfile, join
from random import randint
from PyInstagramAPI import PyInstagramAPI

PhotoPath = "~/igphoto/"  # Change Directory to Folder with Pics that you want to upload
# Change to your Photo Hashtag
IGCaption = "Your Caption Here #hashtag"

os.chdir(PhotoPath)
ListFiles = [f for f in listdir(PhotoPath) if isfile(join(PhotoPath, f))]
print("Total Photo in this folder:" + str(len(ListFiles)))

# Start Login and Uploading Photo
igapi = PyInstagramAPI("login", "password")
igapi.login()  # login

for i in range(len(ListFiles)):
    photo = ListFiles[i]
    print("Progress :" + str([i + 1]) + " of " + str(len(ListFiles)))
    print("Now Uploading this photo to instagram: " + photo)
    igapi.uploadPhoto(photo, caption=IGCaption, upload_id=None)
    # sleep for random between 600 - 1200s
    n = randint(600, 1200)
    print("Sleep upload for seconds: " + str(n))
    time.sleep(n)
# Use text editor to edit the script and type in valid Instagram username/password
# 
# example delete_media
# this example for how to delete self media feed
# have 2 parameter on method deleteMedia( MediaID, MediaType)

from PyInstagramAPI import PyInstagramAPI

# change this username & password
username = '******'
password = '******'

ig = PyInstagramAPI(username, password)

# login 
ig.login() 

# get Self user feed 
ig.getSelfUserFeed()

# get response json and assignment value to MediaList Variable
# dict type data 
MediaList = ig.LastJson 

# get first media for example delete media
Media = MediaList['items'][0]

# get media ID 

MediaID = Media['id']
MediaType = Media['media_type']
예제 #4
0
    """

    followers = []
    next_max_id = True
    while next_max_id:
        # first iteration hack
        if next_max_id is True:
            next_max_id = ''

        _ = api.getUserFollowers(user_id, maxid=next_max_id)
        followers.extend(api.LastJson.get('users', []))
        next_max_id = api.LastJson.get('next_max_id', '')
    return followers


if __name__ == "__main__":
    api = PyInstagramAPI("username", "password")
    api.login()

    # user_id = '1461295173'
    user_id = api.username_id

    # List of all followers
    followers = getTotalFollowers(api, user_id)
    print('Number of followers:', len(followers))

    # Alternatively, use the code below
    # (check evaluation.evaluate_user_followers for further details).
    followers = api.getTotalFollowers(user_id)
    print('Number of followers:', len(followers))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Use text editor to edit the script and type in valid Instagram username/password

from PyInstagramAPI import PyInstagramAPI
import time
from datetime import datetime

user_id = ''

API = PyInstagramAPI("login", "password")
API.login()

API.getUsernameInfo(user_id)
API.LastJson
following = []
next_max_id = True
while next_max_id:
    print(next_max_id)
    # first iteration hack
    if next_max_id is True:
        next_max_id = ''
    _ = API.getUserFollowings(user_id, maxid=next_max_id)
    following.extend(API.LastJson.get('users', []))
    next_max_id = API.LastJson.get('next_max_id', '')

len(following)
unique_following = {f['pk']: f for f in following}
len(unique_following)
예제 #6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Use text editor to edit the script and type in valid Instagram username/password

from PyInstagramAPI import PyInstagramAPI
import urllib

video_url = 'https://instagram.fmad3-2.fna.fbcdn.net/t50.2886-16/17157217_1660580944235536_866261046376005632_n.mp4'  # a valid instagram video
video_local_path = video_url.split("/")[-1]
thumbnail_url = "https://instagram.fmad3-2.fna.fbcdn.net/t51.2885-15/e15/17075853_1759410394387536_3927726791665385472_n.jpg"
thumbnail_local_path = thumbnail_url.split("/")[-1]

urllib.urlretrieve(video_url, video_local_path)
urllib.urlretrieve(thumbnail_url, thumbnail_local_path)

PyInstagramAPI = PyInstagramAPI("login", "password")
PyInstagramAPI.login()  # login
PyInstagramAPI.uploadVideo(video_local_path, thumbnail_local_path, caption="Tortuguero")