From 51846268a9aa8ea12acf5431aab6e84d7f9a07ba Mon Sep 17 00:00:00 2001 From: Ayomide Onigbinde Date: Fri, 4 Jan 2019 10:22:09 +0100 Subject: [PATCH] cleanup for PR #51 --- examples/basic/main.go | 6 +----- examples/extension/main.go | 7 +------ examples/linked-account/main.go | 7 +------ messenger.go | 7 +------ 4 files changed, 4 insertions(+), 23 deletions(-) diff --git a/examples/basic/main.go b/examples/basic/main.go index 8ba35ea..da4c263 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -11,10 +11,6 @@ import ( "github.com/paked/messenger" ) -//profileField is a slice of strings of the user profile field the developer wants access -var ( - profileField = []string{"name", "first_name", "last_name", "profile_pic"} -) var ( verifyToken = flag.String("verify-token", "mad-skrilla", "The token used to verify facebook (required)") verify = flag.Bool("should-verify", false, "Whether or not the app should verify itself") @@ -47,7 +43,7 @@ func main() { client.HandleMessage(func(m messenger.Message, r *messenger.Response) { fmt.Printf("%v (Sent, %v)\n", m.Text, m.Time.Format(time.UnixDate)) - p, err := client.ProfileByID(m.Sender.ID, profileField) + p, err := client.ProfileByID(m.Sender.ID, []string{"name", "first_name", "last_name", "profile_pic"}) if err != nil { fmt.Println("Something went wrong!", err) } diff --git a/examples/extension/main.go b/examples/extension/main.go index e469c4f..5f772f0 100644 --- a/examples/extension/main.go +++ b/examples/extension/main.go @@ -11,11 +11,6 @@ import ( "github.com/paked/messenger" ) -//profileField is a slice of strings of the user profile field the developer wants access -var ( - profileField = []string{"name", "first_name", "last_name", "profile_pic"} -) - var ( serverURL = flag.String("serverURL", "", "The server (webview) URL, must be https (required)") verifyToken = flag.String("verify-token", "mad-skrilla", "The token used to verify facebook (required)") @@ -57,7 +52,7 @@ func main() { client.HandleMessage(func(m messenger.Message, r *messenger.Response) { fmt.Printf("%v (Sent, %v)\n", m.Text, m.Time.Format(time.UnixDate)) - p, err := client.ProfileByID(m.Sender.ID, profileField) + p, err := client.ProfileByID(m.Sender.ID, []string{"name", "first_name", "last_name", "profile_pic"}) if err != nil { fmt.Println("Something went wrong!", err) } diff --git a/examples/linked-account/main.go b/examples/linked-account/main.go index 23a6113..7bb9dc6 100644 --- a/examples/linked-account/main.go +++ b/examples/linked-account/main.go @@ -14,11 +14,6 @@ import ( "github.com/paked/messenger" ) -//profileField is a slice of strings of the user profile field the developer wants access -var ( - profileField = []string{"name", "first_name", "last_name", "profile_pic"} -) - const ( webhooksPath = "/webhooks" loginPath = "/signin" @@ -59,7 +54,7 @@ func main() { client.HandleMessage(func(m messenger.Message, r *messenger.Response) { log.Printf("%v (Sent, %v)\n", m.Text, m.Time.Format(time.UnixDate)) - p, err := client.ProfileByID(m.Sender.ID, profileField) + p, err := client.ProfileByID(m.Sender.ID, []string{"name", "first_name", "last_name", "profile_pic"}) if err != nil { log.Println("Failed to fetch user profile:", err) } diff --git a/messenger.go b/messenger.go index a388b5c..67f43c3 100644 --- a/messenger.go +++ b/messenger.go @@ -5,7 +5,6 @@ import ( "crypto/hmac" "crypto/sha1" "encoding/json" - "errors" "fmt" "io/ioutil" "net/http" @@ -154,7 +153,7 @@ func (m *Messenger) Handler() http.Handler { // According to the messenger docs: https://developers.facebook.com/docs/messenger-platform/identity/user-profile, // Developers must ask for access except for some fields that are accessible without permissions. // -// These fields are +// At the time of writing (2019-01-04), these fields are // - Name // - First Name // - Last Name @@ -168,10 +167,6 @@ func (m *Messenger) ProfileByID(id int64, profileFields []string) (Profile, erro return p, err } - if len(profileFields) == 0 { - return p, errors.New("Profile field cannot be empty") - } - fields := strings.Join(profileFields, ",") req.URL.RawQuery = "fields=" + fields + "&access_token=" + m.token