-
Notifications
You must be signed in to change notification settings - Fork 58
09. Extras
To the goinsta tests, a few pieces of code were written to fetch random accounts from the environment variables, and a .env
file. I noticed myself copying the code over for personal tests, and thus decided to move the code from the tests to the main package. This allow you to set one or more environment variables containing either the clear text credentials, or a base64 encoded goinsta config, and randomly pick an account from the available accounts.
To use these functions either create a file containing the variables (e.g. .env
), or export system variables matching the following pattern:
# Template
INSTAGRAM_ACT_<name>="username:password"
# Example
INSTAGRAM_ACT_admin="admin:Password!"
INSTAGRAM_ACT_second="jokes:onyou"
# Optional, base64 encoded
INSTAGRAM_BASE64_<name>="<base64 encoded config>"
# Example
INSTAGRAM_ACT_one="eyJtZXNzYWdlIjogImhlaGUgeW91IHJvY2siLCAianVuayI6ICJMb3JlbSBpcHN1bSBkb2xvciBzaXQgYW1ldCwgY29uc2VjdGV0dXIgYWRpcGlzY2luZyBlbGl0LCBzZWQgZG8gZWl1c21vZCB0ZW1wb3IgaW5jaWRpZHVudCJ9"
Defining a base64 encoded account is optional, as all plain text accounts will be exported as base64 configs, alongside the plain text. If no base64 variables are found, or one or more plain text accounts have not been converted, all the accounts will be converted into base64 configs.
There are two functions to get a random account from the environment, one to get random plaintext credentials, and one to get a random base64 string. The former should only be used if you know exactly what you are doing, as re-logging in every time you run your program is not ideal.
// Check if a base64 string is present, if one more plain text creds have
// not been converted, convert them.
insta, err := goinsta.EnvRandAcc()
// If you don't want to use the .env in your current working directory,
// use a manual path
insta, err := goinsta.EnvRandAcc("my_instagram_accounts.txt")
// Fetch random plain text credentials
insta, err := goinsta.EnvRandLogin()
// Non-default path
insta, err := goinsta.EnvRandLogin("my_instagram_accounts.txt")
By default, if you add a new plain text account and call EnvRandAcc()
, only that plain text account will be converted into a base64 config. If you want to refresh all accounts, aka re-login for all available credentials, and export a new config, you need to manually call provision.
// Set the second parameter to true if you want to force refresh
err := goinsta.ProvisionEnv(".env", true)
// This will provision only new plain text creds from, and into .env
err := goinsta.ProvisionEnv()
Disclaimer: This code is in no way affiliated with, authorized, maintained, sponsored, or endorsed by Instagram or any of its affiliates or subsidiaries. This is an independent and unofficial API. Use at your own risk. It is prohibited to use this API to spam users or the platform in any way.