diff --git a/examples/basic/main.go b/examples/basic/main.go index f86d6e0..8ba35ea 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -11,6 +11,10 @@ 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") @@ -43,7 +47,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) + p, err := client.ProfileByID(m.Sender.ID, profileField) if err != nil { fmt.Println("Something went wrong!", err) } diff --git a/examples/extension/main.go b/examples/extension/main.go index 679d1c3..e469c4f 100644 --- a/examples/extension/main.go +++ b/examples/extension/main.go @@ -11,6 +11,11 @@ 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)") @@ -52,7 +57,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) + p, err := client.ProfileByID(m.Sender.ID, profileField) if err != nil { fmt.Println("Something went wrong!", err) } diff --git a/examples/linked-account/main.go b/examples/linked-account/main.go index cfde079..1e216f7 100644 --- a/examples/linked-account/main.go +++ b/examples/linked-account/main.go @@ -14,6 +14,11 @@ 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" diff --git a/messenger.go b/messenger.go index 70203e5..a388b5c 100644 --- a/messenger.go +++ b/messenger.go @@ -150,7 +150,15 @@ func (m *Messenger) Handler() http.Handler { return m.mux } -// ProfileByID retrieves the Facebook user profile associated with that ID +// ProfileByID retrieves the Facebook user profile associated with that ID. +// 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 +// - Name +// - First Name +// - Last Name +// - Profile Picture func (m *Messenger) ProfileByID(id int64, profileFields []string) (Profile, error) { p := Profile{} url := fmt.Sprintf("%v%v", ProfileURL, id)