Merge pull request #51 from OAyomide/master
remove default profile fields; fix minor typo
This commit is contained in:
commit
ca367dcfca
@ -43,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)
|
||||
p, err := client.ProfileByID(m.Sender.ID, []string{"name", "first_name", "last_name", "profile_pic"})
|
||||
if err != nil {
|
||||
fmt.Println("Something went wrong!", err)
|
||||
}
|
||||
|
@ -52,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)
|
||||
p, err := client.ProfileByID(m.Sender.ID, []string{"name", "first_name", "last_name", "profile_pic"})
|
||||
if err != nil {
|
||||
fmt.Println("Something went wrong!", err)
|
||||
}
|
||||
|
@ -54,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)
|
||||
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)
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package messenger
|
||||
|
||||
import "time"
|
||||
|
||||
// Message represents a Facebook messenge message.
|
||||
// Message represents a Facebook messenger message.
|
||||
type Message struct {
|
||||
// Sender is who the message was sent from.
|
||||
Sender Sender `json:"-"`
|
||||
|
30
messenger.go
30
messenger.go
@ -25,11 +25,6 @@ const (
|
||||
MessengerProfileURL = "https://graph.facebook.com/v2.6/me/messenger_profile"
|
||||
)
|
||||
|
||||
var (
|
||||
// NOTE: If you change this slice you should update the comment on the ProfileByID function below too.
|
||||
defaultProfileFields = []string{"first_name", "last_name", "profile_pic", "locale", "timezone", "gender"}
|
||||
)
|
||||
|
||||
// Options are the settings used when creating a Messenger client.
|
||||
type Options struct {
|
||||
// Verify sets whether or not to be in the "verify" mode. Used for
|
||||
@ -154,17 +149,16 @@ func (m *Messenger) Handler() http.Handler {
|
||||
return m.mux
|
||||
}
|
||||
|
||||
// ProfileByID retrieves the Facebook user profile associated with that ID
|
||||
// when no profile fields are specified it uses some sane defaults.
|
||||
// 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 default fields are:
|
||||
// - First name
|
||||
// - Last name
|
||||
// - Profile picture
|
||||
// - Locale
|
||||
// - Timezone
|
||||
// - Gender
|
||||
func (m *Messenger) ProfileByID(id int64, profileFields ...string) (Profile, error) {
|
||||
// At the time of writing (2019-01-04), 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)
|
||||
|
||||
@ -173,10 +167,6 @@ func (m *Messenger) ProfileByID(id int64, profileFields ...string) (Profile, err
|
||||
return p, err
|
||||
}
|
||||
|
||||
if len(profileFields) == 0 {
|
||||
profileFields = defaultProfileFields
|
||||
}
|
||||
|
||||
fields := strings.Join(profileFields, ",")
|
||||
|
||||
req.URL.RawQuery = "fields=" + fields + "&access_token=" + m.token
|
||||
@ -242,7 +232,7 @@ func (m *Messenger) GreetingSetting(text string) error {
|
||||
return checkFacebookError(resp.Body)
|
||||
}
|
||||
|
||||
// CallToActionsSetting sends settings for Get Started or Persist Menu
|
||||
// CallToActionsSetting sends settings for Get Started or Persistent Menu
|
||||
func (m *Messenger) CallToActionsSetting(state string, actions []CallToActionsItem) error {
|
||||
d := CallToActionsSetting{
|
||||
SettingType: "call_to_actions",
|
||||
|
@ -2,6 +2,7 @@ package messenger
|
||||
|
||||
// Profile is the public information of a Facebook user
|
||||
type Profile struct {
|
||||
Name string `json:"name"`
|
||||
FirstName string `json:"first_name"`
|
||||
LastName string `json:"last_name"`
|
||||
ProfilePicURL string `json:"profile_pic"`
|
||||
|
Loading…
Reference in New Issue
Block a user