func (s *Session) FBID() string {
	return s.userID
}
FBID returns the authenticated user's FBID.
package fbmsgr
import (
	"bytes"
	"errors"
	"io"
	"math/rand"
	"net/http"
	"net/http/cookiejar"
	"net/url"
	"regexp"
	"strconv"
	"sync"
	"time"
	"github.com/unixpickle/essentials"
	"github.com/yhat/scrape"
	"golang.org/x/net/html"
	"golang.org/x/net/html/atom"
)
const (
	BaseURL          = "https://www.messenger.com"
	SpoofedUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:43.0) Gecko/20100101 Firefox/43.0"
)
type Session struct {
	Client *http.Client
	userID string
	fbDTSGLock sync.Mutex
	fbDTSGTime time.Time
	fbDTSG     string
	defaultStreamLock sync.Mutex
	defaultStream     *EventStream
	randLock sync.Mutex
	randGen  *rand.Rand
}
func Auth(user, password string) (sess *Session, err error) {
	defer essentials.AddCtxTo("fbmsgr: authenticate", &err)
	jar, _ := cookiejar.New(nil)
	client := &http.Client{
		Jar: jar,
	}
	loginPage, err := client.Get(BaseURL + "/")
	if loginPage != nil {
		defer loginPage.Body.Close()
	}
	if err != nil {
		return nil, errors.New("request login page: " + err.Error())
	}
	root, err := html.Parse(loginPage.Body)
	if err != nil {
		return nil, errors.New("parse login page: " + err.Error())
	}
	formValues, action, err := loginFormValues(root)
	if err != nil {
		return nil, errors.New("read login form: " + err.Error())
	}
	if err := requestLoginCookies(client, root); err != nil {
		return nil, errors.New("gather cookies: " + err.Error())
	}
	formValues.Set("email", user)
	formValues.Set("pass", password)
	formValues.Set("persistent", "1")
	formValues.Set("login", "1")
	body := []byte(formValues.Encode())
	req, err := http.NewRequest("POST", BaseURL+action, bytes.NewBuffer(body))
	if err != nil {
		return nil, errors.New("create login request: " + err.Error())
	}
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	req.Header.Set("Content-Length", strconv.Itoa(len(body)))
	req.Header.Set("User-Agent", SpoofedUserAgent)
	req.Header.Set("Referer", BaseURL+"/")
	postRes, err := client.Do(req)
	if postRes != nil {
		defer postRes.Body.Close()
	}
	if err != nil {
		return nil, errors.New("failed to login: " + err.Error())
	}
	if postRes.Request.URL.Path == "/" {
		return sessionForHomepage(client, postRes.Body)
	}
	return nil, errors.New("login failed")
}