-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathget_profile.py
54 lines (42 loc) · 1.42 KB
/
get_profile.py
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
"""
Example call to fetch the member profile for the authorized member.
The 3-legged member access token should include the 'r_liteprofile' scope, which
is part of the Sign In With LinkedIn API product.
"""
import os, sys
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv())
from linkedin_api.clients.restli.client import RestliClient
ACCESS_TOKEN = os.getenv("ACCESS_TOKEN")
if ACCESS_TOKEN is None:
raise Exception(
'A valid access token must be defined in the /examples/.env file under the variable name "ACCESS_TOKEN"'
)
PROFILE_RESOURCE = "/me"
restli_client = RestliClient()
"""
Basic usage to fetch current member profile
"""
response = restli_client.get(resource_path=PROFILE_RESOURCE, access_token=ACCESS_TOKEN)
print("Basic usage:", response.entity)
"""
Usage with field projections
"""
response = restli_client.get(
resource_path=PROFILE_RESOURCE,
access_token=ACCESS_TOKEN,
query_params={"fields": "id,firstName:(localized),lastName"},
)
print("\n\nUsage with field projections:", response.entity)
"""
Usage with decoration of displayImage
"""
response = restli_client.get(
resource_path=PROFILE_RESOURCE,
access_token=ACCESS_TOKEN,
query_params={
"projection": "(id,firstName,lastName,profilePicture(displayImage~:playableStreams))"
},
)
print("\n\nUsage with decoration:", response.entity)