Merge pull request #49 from EddyTravels/feature/profile-fields
Allow specifying which profile fields to pull
This commit is contained in:
commit
7fbedb40b4
28
messenger.go
28
messenger.go
@ -16,8 +16,6 @@ const (
|
|||||||
// ProfileURL is the API endpoint used for retrieving profiles.
|
// ProfileURL is the API endpoint used for retrieving profiles.
|
||||||
// Used in the form: https://graph.facebook.com/v2.6/<USER_ID>?fields=<PROFILE_FIELDS>&access_token=<PAGE_ACCESS_TOKEN>
|
// Used in the form: https://graph.facebook.com/v2.6/<USER_ID>?fields=<PROFILE_FIELDS>&access_token=<PAGE_ACCESS_TOKEN>
|
||||||
ProfileURL = "https://graph.facebook.com/v2.6/"
|
ProfileURL = "https://graph.facebook.com/v2.6/"
|
||||||
// ProfileFields is a list of JSON field names which will be populated by the profile query.
|
|
||||||
ProfileFields = "first_name,last_name,profile_pic,locale,timezone,gender"
|
|
||||||
// SendSettingsURL is API endpoint for saving settings.
|
// SendSettingsURL is API endpoint for saving settings.
|
||||||
SendSettingsURL = "https://graph.facebook.com/v2.6/me/thread_settings"
|
SendSettingsURL = "https://graph.facebook.com/v2.6/me/thread_settings"
|
||||||
|
|
||||||
@ -27,6 +25,11 @@ 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
|
||||||
@ -151,8 +154,17 @@ func (m *Messenger) Handler() http.Handler {
|
|||||||
return m.mux
|
return m.mux
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProfileByID retrieves the Facebook user associated with that ID
|
// ProfileByID retrieves the Facebook user profile associated with that ID
|
||||||
func (m *Messenger) ProfileByID(id int64) (Profile, error) {
|
// when no profile fields are specified it uses some sane defaults.
|
||||||
|
//
|
||||||
|
// These default fields are:
|
||||||
|
// - First name
|
||||||
|
// - Last name
|
||||||
|
// - Profile picture
|
||||||
|
// - Locale
|
||||||
|
// - Timezone
|
||||||
|
// - 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)
|
||||||
|
|
||||||
@ -161,7 +173,13 @@ func (m *Messenger) ProfileByID(id int64) (Profile, error) {
|
|||||||
return p, err
|
return p, err
|
||||||
}
|
}
|
||||||
|
|
||||||
req.URL.RawQuery = "fields=" + ProfileFields + "&access_token=" + m.token
|
if len(profileFields) == 0 {
|
||||||
|
profileFields = defaultProfileFields
|
||||||
|
}
|
||||||
|
|
||||||
|
fields := strings.Join(profileFields, ",")
|
||||||
|
|
||||||
|
req.URL.RawQuery = "fields=" + fields + "&access_token=" + m.token
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
|
Loading…
Reference in New Issue
Block a user