-
Notifications
You must be signed in to change notification settings - Fork 60
10. Settings & Logging
Goinsta provides access to some settings to customize the behavior.
Goinsta allows you to set a proxy if you want redirect the requests over another IP, or to observe the requests happening. There are two ways to set a proxy, the first is through the environment variables, the second is by calling insta.SetProxy.
Using environment variables will set the proxy righ at the initialization of the HTTP client. This will ensure all request are made over the proxy.
export HTTP_PROXY="http://[user]:[pass]@[proxy_ip]:[proxy_port]/"
export HTTPS_PROXY="http://[user]:[pass]@[proxy_ip]:[proxy_port]/"If you set the proxy through gointsa, be sure to set the proxy before calling login, as that is when the first requests will be made. Also, be sure to set the proxy again after importing a configuration. The config does not store or set proxy settings. Furthermore, it is important to set the skipSync flag in the import method, as otherwise it will make a single request without a proxy, and thus leak your real IP. You can always call insta.Account.Sync() after import to compensate for that.
// Set skip sync to true to prevent requests on import
insta, err := goinsta.Import(".goinsta", true)
if err != nil {
log.Fatal(err)
}
//
// URL: the first param is the proxy URL
//
// INSECURE: the second argument dictates whether the SSL certificate has to be trusted or not.
// If you set this to false, be sure to import the proxy certificate in your OS
//
// FORCE_HTTP2: the third arg dictates whether an http2 transport layer will be used.
// All Instagram requests will be HTTP2 enabled, but I noticed that sometimes
// the proxy will cause it to downgrade to HTTP1.1, therefore I recommend setting
// this to true. If you encounter problems please let me know and set it to false.
//
err := insta.SetProxy("http://127.0.0.1:8080", false, true)
if err != nil {
log.Fatal(err)
}
// Optional
err := insta.Account.Sync()
if err != nil {
log.Fatal(err)
}As goinsta utilizes the mobile API, a device is also emulated. To achieve this it uses various identifiers set as fields of the Instagram struct. One of these is the Device struct, containing fields such as the make and model of the phone, and the android version it uses. By default, goinsta emulates a Galaxy S10+, and the settings for an LG G6 have also been provided. You can however emulate any phone you would like. To find the right values, you can look at device specs, or deduce them existing user agents (example).
Other unique identifiers used to call the Instagram API are device id, phone id, uuid, and device family id. These will be automatically generated upon calling goinsta.New, if you wish to emulate another existing device however, you can set these values manually. All the device settings and unique identifiers only need to be set once after the initial creation of the Instagram instance, right after calling goinsta.New(user, pass), if you wish to use manual ones, as the device will be saved in the config, and thus persist throughout exports. To stress again, this is not required, and fully optional.
insta, err := goinsta.New(user, pass)
if err != nil {
return err
}
insta.SetDevice(
// Default phone used as example, fill in any legitimate values here
goinsta.Device{
Manufacturer: "samsung",
Model: "SM-G975F",
CodeName: "beyond2",
AndroidVersion: 30,
AndroidRelease: 11,
ScreenDpi: "560dpi",
ScreenResolution: "1440x2898",
Chipset: "exynos9820",
},
)
insta.SetDeviceID("android-1923fjnma8123")
insta.SetUUID("71cd1aec-e146-4380-8d60-d216127c7b4e")
insta.SetPhoneID("fbf767a4-260a-490d-bcbb-ee7c9ed7c576")
insta.SetFamilyID("8b13e7b3-28f7-4e05-9474-358c6602e3f8")
insta.SetAdID("5b23a92b-3228-4cff-b6ab-3199f531f05b")Most of the errors generated by goinsta are directly returned, as idiomatic Go would want it. There are some possibilities for non-fatal errors, and info messages, however. For example, some endpoints should be called, in accordance with the app sequences, although some calls are quite trivial, and some responses are flat out ignored. They do need to be called, but if their HTTP response code is not 200 not the entire sequence should error out because of them. Some endpoints are known to be sensitive and often return a status code 429, Too Many Requests, even in the official app. In these situations, the errors will be passed to the Instagram.WarnHandler, or Instagram.InfoHandler, as they should be noted, but no direct action needs to be taken. These handlers are functions with a func(...interface{}) signature. The default handlers simply redirect the arguments into fmt.Println(), but for some situations, it might be desirable to pass them to a proper logger.
A debug handler has now also been added. Currently, setting insta.Debug = true will log out every request made, along with the response in json format. To set debug to true, you can also set the GOINSTA_DEBUG env variable, e.g. GOINSTA_DEBUG=true go run main.go. If you encounter an issue, or undescriptive error, you can use this to log out the requests made. When opening an issue, you can then add the debug output, so it is easier to fix.
...
insta.SetInfoHandler(someFunc)
insta.SetWarnHandler(someFunc)
insta.SetDebugHandler(someFunc)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.