Skip to content

Commit

Permalink
Add picture field to facebook User struct
Browse files Browse the repository at this point in the history
* Add the Facebook user's picture to the User struct
since it requires no additional permissions and is
often used in login flows

Docs: https://developers.facebook.com/docs/graph-api/overview
  • Loading branch information
mtibben authored and dghubble committed Apr 28, 2023
1 parent 8c1deb9 commit 113f452
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions facebook/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ const facebookAPI = "https://graph.facebook.com/v2.9/"
//
// Note that user ids are unique to each app.
type User struct {
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Picture struct {
Data struct {
URL string `json:"url"`
} `json:"data"`
} `json:"picture"`
}

// client is a Facebook client for obtaining the current User.
Expand All @@ -36,6 +41,6 @@ func (c *client) Me() (*User, *http.Response, error) {
// Facebook returns JSON as Content-Type text/javascript :(
// Set Accept header to receive proper Content-Type application/json
// so Sling will decode into the struct
resp, err := c.sling.New().Set("Accept", "application/json").Get("me?fields=name,email").ReceiveSuccess(user)
resp, err := c.sling.New().Set("Accept", "application/json").Get("me?fields=name,email,picture").ReceiveSuccess(user)
return user, resp, err
}

0 comments on commit 113f452

Please sign in to comment.