Skip to content
This repository was archived by the owner on Jan 1, 2023. It is now read-only.

Commit ca367dc

Browse files
authored
Merge pull request #51 from OAyomide/master
remove default profile fields; fix minor typo
2 parents 8a7cca0 + 5184626 commit ca367dc

6 files changed

Lines changed: 16 additions & 25 deletions

File tree

examples/basic/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func main() {
4343
client.HandleMessage(func(m messenger.Message, r *messenger.Response) {
4444
fmt.Printf("%v (Sent, %v)\n", m.Text, m.Time.Format(time.UnixDate))
4545

46-
p, err := client.ProfileByID(m.Sender.ID)
46+
p, err := client.ProfileByID(m.Sender.ID, []string{"name", "first_name", "last_name", "profile_pic"})
4747
if err != nil {
4848
fmt.Println("Something went wrong!", err)
4949
}

examples/extension/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func main() {
5252
client.HandleMessage(func(m messenger.Message, r *messenger.Response) {
5353
fmt.Printf("%v (Sent, %v)\n", m.Text, m.Time.Format(time.UnixDate))
5454

55-
p, err := client.ProfileByID(m.Sender.ID)
55+
p, err := client.ProfileByID(m.Sender.ID, []string{"name", "first_name", "last_name", "profile_pic"})
5656
if err != nil {
5757
fmt.Println("Something went wrong!", err)
5858
}

examples/linked-account/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func main() {
5454
client.HandleMessage(func(m messenger.Message, r *messenger.Response) {
5555
log.Printf("%v (Sent, %v)\n", m.Text, m.Time.Format(time.UnixDate))
5656

57-
p, err := client.ProfileByID(m.Sender.ID)
57+
p, err := client.ProfileByID(m.Sender.ID, []string{"name", "first_name", "last_name", "profile_pic"})
5858
if err != nil {
5959
log.Println("Failed to fetch user profile:", err)
6060
}

message.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package messenger
22

33
import "time"
44

5-
// Message represents a Facebook messenge message.
5+
// Message represents a Facebook messenger message.
66
type Message struct {
77
// Sender is who the message was sent from.
88
Sender Sender `json:"-"`

messenger.go

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ const (
2525
MessengerProfileURL = "https://graph.facebook.com/v2.6/me/messenger_profile"
2626
)
2727

28-
var (
29-
// NOTE: If you change this slice you should update the comment on the ProfileByID function below too.
30-
defaultProfileFields = []string{"first_name", "last_name", "profile_pic", "locale", "timezone", "gender"}
31-
)
32-
3328
// Options are the settings used when creating a Messenger client.
3429
type Options struct {
3530
// Verify sets whether or not to be in the "verify" mode. Used for
@@ -154,17 +149,16 @@ func (m *Messenger) Handler() http.Handler {
154149
return m.mux
155150
}
156151

157-
// ProfileByID retrieves the Facebook user profile associated with that ID
158-
// when no profile fields are specified it uses some sane defaults.
159-
//
160-
// These default fields are:
161-
// - First name
162-
// - Last name
163-
// - Profile picture
164-
// - Locale
165-
// - Timezone
166-
// - Gender
167-
func (m *Messenger) ProfileByID(id int64, profileFields ...string) (Profile, error) {
152+
// ProfileByID retrieves the Facebook user profile associated with that ID.
153+
// According to the messenger docs: https://developers.facebook.com/docs/messenger-platform/identity/user-profile,
154+
// Developers must ask for access except for some fields that are accessible without permissions.
155+
//
156+
// At the time of writing (2019-01-04), these fields are
157+
// - Name
158+
// - First Name
159+
// - Last Name
160+
// - Profile Picture
161+
func (m *Messenger) ProfileByID(id int64, profileFields []string) (Profile, error) {
168162
p := Profile{}
169163
url := fmt.Sprintf("%v%v", ProfileURL, id)
170164

@@ -173,10 +167,6 @@ func (m *Messenger) ProfileByID(id int64, profileFields ...string) (Profile, err
173167
return p, err
174168
}
175169

176-
if len(profileFields) == 0 {
177-
profileFields = defaultProfileFields
178-
}
179-
180170
fields := strings.Join(profileFields, ",")
181171

182172
req.URL.RawQuery = "fields=" + fields + "&access_token=" + m.token
@@ -242,7 +232,7 @@ func (m *Messenger) GreetingSetting(text string) error {
242232
return checkFacebookError(resp.Body)
243233
}
244234

245-
// CallToActionsSetting sends settings for Get Started or Persist Menu
235+
// CallToActionsSetting sends settings for Get Started or Persistent Menu
246236
func (m *Messenger) CallToActionsSetting(state string, actions []CallToActionsItem) error {
247237
d := CallToActionsSetting{
248238
SettingType: "call_to_actions",

profile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package messenger
22

33
// Profile is the public information of a Facebook user
44
type Profile struct {
5+
Name string `json:"name"`
56
FirstName string `json:"first_name"`
67
LastName string `json:"last_name"`
78
ProfilePicURL string `json:"profile_pic"`

0 commit comments

Comments
 (0)