siongui / instago

Download/access photos, videos, stories, story highlights, postlives, following and followers of Instagram
The Unlicense
104 stars 10 forks source link

Get Cookies Without Browser Extension. #1

Closed s0kil closed 4 years ago

s0kil commented 6 years ago

Why not get cookies using an HTTP request? The browser extension is too much hassle.


package main

import (
    "bytes"
    "fmt"
    "net/http"
)

var username = "InstaUsername"
var password = "InstaPassword"

func main() {
    url := "https://www.instagram.com/accounts/login/ajax/"

    var params = []byte(fmt.Sprintf(`username=%s&password=%s&queryParams={}`, username, password))
    req, err := http.NewRequest("POST", url, bytes.NewBuffer(params))
    req.Header.Set("user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.139 Chrome/66.0.3359.139 Safari/537.36")
    req.Header.Set("content-type", "application/x-www-form-urlencoded")
    req.Header.Set("x-requested-with", "XMLHttpRequest")
    req.Header.Set("x-csrftoken", "Xz7lgke9oJh9CV8c2HjY2o0tB4EvQedb")
    req.Header.Set("cookie", "csrftoken=Xz7lgke9oJh9CV8c2HjY2o0tB4EvQedb; rur=FTW; mid=Wv1kwwAEAAF10fw8f1pJ9zUc4HcT")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    fmt.Println("response Cookies:", resp.Cookies())
}
siongui commented 6 years ago

Good idea! But I use Facebook login. Does the sample code here also work for Facebook login? Thanks

s0kil commented 6 years ago

I don't think so.