예제 #1
0
func (fbs *Stub) Subscribe(s *admin.Status) {
	v := url.Values{}
	v.Add("object", "user")
	v.Add("fields", "events")
	v.Add("verify_token", fbs.verifyToken)
	v.Add("callback_url", s.AppDomain+"fbsub/cb")
	v.Add(fbs.accessToken[0], fbs.accessToken[1])
	s.Log["FB Subscription URL"] = admin.NewLog(true, &admin.FBSubscriptionURL{
		U: SubURL,
		V: v,
	})
	res, err := http.PostForm(SubURL, v)
	ok := err == nil && res.StatusCode == http.StatusOK
	s.Log["FB Subscription Response"] = admin.NewLog(ok, res)
}
예제 #2
0
func (fbs *Stub) VerifySub(s *admin.Status, w http.ResponseWriter, r *http.Request) (int, []byte) {
	ok := r.FormValue("hub.mode") == "subscribe" && r.FormValue("hub.verify_token") == fbs.verifyToken
	s.Log["FB Verification Request"] = admin.NewLog(ok, r)
	if !ok {
		return http.StatusBadRequest, []byte("hub.mode or verify_token mismatch")
	}
	return http.StatusOK, []byte(r.FormValue("hub.challenge"))
}
예제 #3
0
파일: fb.go 프로젝트: ranveerkunal/fb
func (fbs *Stub) OAuth(s *admin.Status) error {
	v := url.Values{}
	v.Add("client_id", *ClientID)
	v.Add("client_secret", *ClientSecret)
	v.Add("grant_type", "client_credentials")
	res, err := http.Get(fmt.Sprintf("%s/oauth/access_token?%s", EndPoint, v.Encode()))
	ok := err == nil && res.StatusCode == http.StatusOK
	s.Log["FB Access Token"] = admin.NewLog(ok, res)
	if !ok {
		return err
	}
	body, err := ioutil.ReadAll(res.Body)
	fbs.accessToken = strings.Split(string(body), "=")
	res.Body.Close()
	return err
}