DEV Community

David Hwang
David Hwang

Posted on

5/20 TIL: Go Social Media Login

For the social media login:

  • Create a req variable by passing in the login API url to the http.NewRequest()
var req = http.NewRequest("GET", {url}, nil)
Enter fullscreen mode Exit fullscreen mode
  • Add the Bearer {accessToken} to the Authorization header
req.Headers.Add(("Authorization", "Bearer " + accessToken)
Enter fullscreen mode Exit fullscreen mode
  • Pass that req variable into the Client.Do() and store the response in the response variable
var res = Client.Do(req)
Enter fullscreen mode Exit fullscreen mode
  • Create a struct with an ID field to store the value returned from the response
type socialResponse struct {
    ID int `json:"id"`
}
Enter fullscreen mode Exit fullscreen mode
  • json.NewDecoder(response.Body).Decode(&socialResponse) to pass the json data into our struct

Top comments (0)