File size: 829 Bytes
fb07b17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
from agents import function_tool
from dotenv import find_dotenv, load_dotenv
import os


# Constants
LINKEDIN_ACCESS_TOKEN = os.getenv("LINKEDIN_ACCESS_TOKEN")

load_dotenv(find_dotenv())

HEADERS = {
    "Authorization": f"Bearer {LINKEDIN_ACCESS_TOKEN}",
    "Content-Type": "application/json",
}


@function_tool
def get_user_info():
    """
    Retrieve LinkedIn user profile information using the /userinfo endpoint.

    Returns:
        dict: User profile information or None if an error occurs.
    """
    url = "https://api.linkedin.com/v2/userinfo"

    try:
        response = requests.get(url, headers=HEADERS)
        response.raise_for_status()
        return response.json()
    except requests.exceptions.RequestException as e:
        print(f"Error fetching user info: {e}")
        return None