1
0
mirror of synced 2024-11-29 00:26:12 +03:00

Merge pull request #51 from OAyomide/master

remove default profile fields; fix minor typo
This commit is contained in:
Harrison Shoebridge 2019-01-04 20:35:45 +11:00 committed by GitHub
commit ca367dcfca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 25 deletions

View File

@ -43,7 +43,7 @@ func main() {
client.HandleMessage(func(m messenger.Message, r *messenger.Response) { client.HandleMessage(func(m messenger.Message, r *messenger.Response) {
fmt.Printf("%v (Sent, %v)\n", m.Text, m.Time.Format(time.UnixDate)) 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 { if err != nil {
fmt.Println("Something went wrong!", err) fmt.Println("Something went wrong!", err)
} }

View File

@ -52,7 +52,7 @@ func main() {
client.HandleMessage(func(m messenger.Message, r *messenger.Response) { client.HandleMessage(func(m messenger.Message, r *messenger.Response) {
fmt.Printf("%v (Sent, %v)\n", m.Text, m.Time.Format(time.UnixDate)) 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 { if err != nil {
fmt.Println("Something went wrong!", err) fmt.Println("Something went wrong!", err)
} }

View File

@ -54,7 +54,7 @@ func main() {
client.HandleMessage(func(m messenger.Message, r *messenger.Response) { client.HandleMessage(func(m messenger.Message, r *messenger.Response) {
log.Printf("%v (Sent, %v)\n", m.Text, m.Time.Format(time.UnixDate)) 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 { if err != nil {
log.Println("Failed to fetch user profile:", err) log.Println("Failed to fetch user profile:", err)
} }

View File

@ -2,7 +2,7 @@ package messenger
import "time" import "time"
// Message represents a Facebook messenge message. // Message represents a Facebook messenger message.
type Message struct { type Message struct {
// Sender is who the message was sent from. // Sender is who the message was sent from.
Sender Sender `json:"-"` Sender Sender `json:"-"`

View File

@ -25,11 +25,6 @@ const (
MessengerProfileURL = "https://graph.facebook.com/v2.6/me/messenger_profile" 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. // Options are the settings used when creating a Messenger client.
type Options struct { type Options struct {
// Verify sets whether or not to be in the "verify" mode. Used for // 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 return m.mux
} }
// ProfileByID retrieves the Facebook user profile associated with that ID // ProfileByID retrieves the Facebook user profile associated with that ID.
// when no profile fields are specified it uses some sane defaults. // 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: // At the time of writing (2019-01-04), these fields are
// - First name // - Name
// - Last name // - First Name
// - Profile picture // - Last Name
// - Locale // - Profile Picture
// - Timezone func (m *Messenger) ProfileByID(id int64, profileFields []string) (Profile, error) {
// - Gender
func (m *Messenger) ProfileByID(id int64, profileFields ...string) (Profile, error) {
p := Profile{} p := Profile{}
url := fmt.Sprintf("%v%v", ProfileURL, id) url := fmt.Sprintf("%v%v", ProfileURL, id)
@ -173,10 +167,6 @@ func (m *Messenger) ProfileByID(id int64, profileFields ...string) (Profile, err
return p, err return p, err
} }
if len(profileFields) == 0 {
profileFields = defaultProfileFields
}
fields := strings.Join(profileFields, ",") fields := strings.Join(profileFields, ",")
req.URL.RawQuery = "fields=" + fields + "&access_token=" + m.token req.URL.RawQuery = "fields=" + fields + "&access_token=" + m.token
@ -242,7 +232,7 @@ func (m *Messenger) GreetingSetting(text string) error {
return checkFacebookError(resp.Body) 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 { func (m *Messenger) CallToActionsSetting(state string, actions []CallToActionsItem) error {
d := CallToActionsSetting{ d := CallToActionsSetting{
SettingType: "call_to_actions", SettingType: "call_to_actions",

View File

@ -2,6 +2,7 @@ package messenger
// Profile is the public information of a Facebook user // Profile is the public information of a Facebook user
type Profile struct { type Profile struct {
Name string `json:"name"`
FirstName string `json:"first_name"` FirstName string `json:"first_name"`
LastName string `json:"last_name"` LastName string `json:"last_name"`
ProfilePicURL string `json:"profile_pic"` ProfilePicURL string `json:"profile_pic"`