github.com/gkstretton/dark/services/goo@v0.0.0-20231114224855-2d1a2074d446/socialmedia/insta.go (about)

     1  package socialmedia
     2  
     3  import (
     4  	"os"
     5  
     6  	// This api is great!!!
     7  	// https://github.com/Davincible/goinsta/wiki/01.-Getting-Started
     8  	"github.com/Davincible/goinsta/v3"
     9  )
    10  
    11  const path = ".goinsta"
    12  
    13  func main() {
    14  	insta, err := goinsta.Import(path)
    15  	defer insta.Export(path)
    16  	bail(err)
    17  	f, err := os.Open("/mnt/md0/light-stores/session_content/latest_production/dslr/post/0001.jpg")
    18  	bail(err)
    19  	item, err := insta.Upload(&goinsta.UploadOptions{
    20  		File:    f,
    21  		Caption: "api test",
    22  	})
    23  	_ = item
    24  	bail(err)
    25  }
    26  
    27  func bail(err error) {
    28  	if err != nil {
    29  		panic(err)
    30  	}
    31  }
    32  
    33  func login() {
    34  	insta := goinsta.New("astudyoflight_", "[password]")
    35  
    36  	// Only call Login the first time you login. Next time import your config
    37  	if err := insta.Login(); err != nil {
    38  		panic(err)
    39  	}
    40  
    41  	// Export your configuration
    42  	// after exporting you can use Import function instead of New function.
    43  	// insta, err := goinsta.Import("~/.goinsta")
    44  	// it's useful when you want use goinsta repeatedly.
    45  	// Export is deffered because every run insta should be exported at the end of the run
    46  	//   as the header cookies change constantly.
    47  	defer insta.Export(".goinsta")
    48  }