-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.go
56 lines (42 loc) · 1.09 KB
/
profile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package golinkedin
import (
"encoding/json"
"fmt"
"io"
"net/http"
)
type ProfileInformation struct {
// ProfileID represents the ID every linkedin profile has.
Id string `json:"id"`
// User's FirstName
FirstName string `json:"localizedFirstName"`
// User's LastName
LastName string `json:"localizedLastName"`
}
var (
ProfileURL = "https://api.linkedin.com/v2/me"
)
/*
After than Callback, you take Profile information with this function.
Create route for this.
*/
func (ln *Linkedin) Profile(token string) (*ProfileInformation, error) {
authorization := fmt.Sprintf("Bearer %s", token)
client := http.Client{}
req, _ := http.NewRequest("GET", ProfileURL, nil)
req.Header = http.Header{
"Content-Type": {"application/json"},
"Authorization": {authorization},
}
res, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("http request error: %s", err.Error())
}
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("read body error: %s", err.Error())
}
var profile ProfileInformation
_ = json.Unmarshal(body, &profile)
return &profile, nil
}