import { IgApiClient } from '../src' ; import { readFile } from 'fs' ; import { promisify } from 'util' ; const readFileAsync = promisify ( readFile ) ; const ig = new IgApiClient ( ) ; async function login ( ) { ig . state . generateDevice ( process . env . IG_USERNAME ) ; ig . state . proxyUrl = process . env . IG_PROXY ; await ig . account . login ( process . env . IG_USERNAME , process . env . IG_PASSWORD ) ; } ( async ( ) => { await login ( ) ; const path = './myPicture.jpg' ; const { latitude , longitude , searchQuery } = { latitude : 0.0 , longitude : 0.0 , searchQuery : 'place' , } ; /**
     * Get the place
     * If searchQuery is undefined, you'll get the nearest places to your location
     * this is the same as in the upload (-configure) dialog in the app
     */ const locations = await ig . search . location ( latitude , longitude , searchQuery ) ; /**
     * Get the first venue
     * In the real world you would check the returned locations
     */ const mediaLocation = locations [ 0 ] ; console . log ( mediaLocation ) ; const publishResult = await ig . publish . photo ( { file : await readFileAsync ( path ) , caption : 'my caption' , location : mediaLocation , usertags : { in : [ await generateUsertagFromName ( 'instagram' , 0.5 , 0.5 ) , ] , } , } ) ; console . log ( publishResult ) ; } ) ( ) ; param name param x param y async function generateUsertagFromName ( name , x , y ) { x = clamp ( x , 0.0001 , 0.9999 ) ; y = clamp ( y , 0.0001 , 0.9999 ) ; const { pk } = await ig . user . searchExact ( name ) ; return { user_id : pk , position : [ x , y ] , } ; } param value param min param max const clamp = ( value , min , max ) => Math . max ( Math . min ( value , max ) , min ) ;