示例#1
0
func main() {
	config, err := util.LoadConfig(configFile)
	util.FailOnError(err)

	if config.ClientID == "" || config.ClientSecret == "" {
		err = fmt.Errorf("This app requires a registered API client. Please set your `client_id`, and `client_secret` config in '%v'.\n", configFile)
		util.FailOnError(err)
	}

	igConf = &oauth2.Config{
		ClientID:     config.ClientID,
		ClientSecret: config.ClientSecret,
		RedirectURL:  redirectURL,
		Endpoint: oauth2.Endpoint{
			AuthURL:  instagramAuthURL,
			TokenURL: instagramTokenURL,
		},
		Scopes: []string{
			"basic",
			"public_content",
			"follower_list",
			"comments",
			"relationships",
			"likes",
		},
	}

	http.HandleFunc("/", Home)
	http.HandleFunc("/handshake", Handshake)
	fmt.Printf("Listening and serving HTTP on %s\n", serverPort)
	http.ListenAndServe(serverPort, nil)
}
示例#2
0
func FollowsBack(c *cli.Context) {
	following, _, err := client.Relationships.Follows("")
	util.FailOnError(err)
	followers, _, err := client.Relationships.FollowedBy("")
	util.FailOnError(err)

	fmt.Println("Users who are not following you back:")
	var u []instagram.User
	if c.Bool("me") {
		u = getNonFollowers(followers, following)
	} else {
		u = getNonFollowers(following, followers)
	}
	_ = printUsers(u)
}
示例#3
0
func Following(c *cli.Context) {
	following, _, err := client.Relationships.Follows("")
	util.FailOnError(err)

	fmt.Println("Users who you are following:")
	_ = printUsers(following)
}
示例#4
0
func Followers(c *cli.Context) {
	followers, _, err := client.Relationships.FollowedBy("")
	util.FailOnError(err)

	fmt.Println("Users who are following you:")
	_ = printUsers(followers)
}
示例#5
0
func Unfollowed(c *cli.Context) {
	// Load history
	f, err := os.Open(followersFile)

	var history []instagram.User
	var fs os.FileInfo

	// Not running for the first time
	if err == nil {
		err = json.NewDecoder(f).Decode(&history)
		util.FailOnError(err)

		fs, err = f.Stat()
		util.FailOnError(err)
		fmt.Printf("Last modified: %v\n", fs.ModTime())
	} else {
		log.Println(err)
		log.Println("Running the command for the first time. You should have received a 'no such file or directory' error.")
	}

	defer f.Close()

	// Load current followers
	followers, _, err := client.Relationships.FollowedBy("")
	util.FailOnError(err)

	fmt.Println("Users who have unfollowed you (since you last ran the command):")

	// Match history with current followers
	u := getNonFollowers(history, followers)
	total := printUsers(u)

	// Save current followers for future reference
	if fs == nil || total != 0 {
		d, err := json.Marshal(followers)
		util.FailOnError(err)

		err = ioutil.WriteFile(followersFile, d, 0644)
		util.FailOnError(err)
	}
}
示例#6
0
func main() {
	// Load config
	if _, err := os.Stat(configFile); os.IsNotExist(err) {
		err = fmt.Errorf("The configuration file ('%s') cannot be found.\n", configFile)
		util.FailOnError(err)
	}

	config, err := util.LoadConfig(configFile)
	util.FailOnError(err)

	if config.AccessToken == "" {
		err = fmt.Errorf("This app requires an authenticated user. Please set your `access_token` config in '%v'.\n", configFile)
		util.FailOnError(err)
	}

	// Create an Instagram client
	client = instagram.NewClient(nil)
	client.ClientID = config.ClientID
	client.ClientSecret = config.ClientSecret
	client.AccessToken = config.AccessToken

	// Commands
	commands := []cli.Command{
		{
			Name:    "Followers",
			Aliases: []string{"fl"},
			Usage:   "Returns a list of users who are following you",
			Action:  Followers,
		},
		{
			Name:    "Following",
			Aliases: []string{"fw"},
			Usage:   "Returns a list of users who you are following",
			Action:  Following,
		},
		{
			Name:    "FollowsBack",
			Aliases: []string{"fb"},
			Usage:   "Returns a list of users who are not following you back",
			Flags: []cli.Flag{
				cli.BoolFlag{Name: "me", Usage: "Returns a list of users YOU are not following back"},
			},
			Action: FollowsBack,
		},
		{
			Name:    "Unfollowed",
			Aliases: []string{"un"},
			Usage:   "Returns a list of users who unfollowed you (since you last ran the command)",
			Action:  Unfollowed,
		},
	}

	// Create CLI
	app := cli.NewApp()
	app.Name = "instafollowers"
	app.Authors = []cli.Author{cli.Author{"Ian Lai", "*****@*****.**"}}
	app.Usage = "Manage your Instagram followers"
	app.Version = "1.4.6"
	app.Commands = commands
	app.Run(os.Args)
}