-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_linkedin_api.py
More file actions
146 lines (125 loc) · 5.13 KB
/
test_linkedin_api.py
File metadata and controls
146 lines (125 loc) · 5.13 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""
Test script to check LinkedIn API response locally.
Tests both the deployed backend and the RapidAPI directly.
"""
import requests
import json
USERNAME = "satyam-yada"
# ==============================
# Test 1: Local Backend API
# ==============================
print("=" * 60)
print(f"TEST 1: Calling LOCAL backend API for username: {USERNAME}")
print("=" * 60)
local_url = f"http://127.0.0.1:8000/api/linkedin/{USERNAME}/"
print(f"URL: {local_url}")
try:
response = requests.get(local_url, timeout=30)
print(f"Status Code: {response.status_code}")
print(f"Headers: {dict(response.headers)}")
try:
data = response.json()
print("\n--- Response JSON ---")
print(json.dumps(data, indent=2))
# Check key fields
if "error" in data:
print(f"\n❌ ERROR from API: {data['error']}")
else:
print(f"\n✅ Username: {data.get('Username', 'MISSING')}")
print(f"✅ ProfilePicture: {data.get('ProfilePicture', 'MISSING')}")
print(f"✅ Location: {data.get('Location', 'MISSING')}")
print(f"✅ Skills count: {len(data.get('Skills', []))}")
print(f"✅ Position count: {len(data.get('Position', []))}")
print(f"✅ Education count: {len(data.get('Education', []))}")
except json.JSONDecodeError:
print(f"\n❌ Response is NOT valid JSON!")
print(f"Raw response: {response.text[:500]}")
except requests.ConnectionError:
print("❌ Could not connect to local backend. Is 'python manage.py runserver' running?")
except requests.Timeout:
print("❌ Request timed out after 30 seconds")
except Exception as e:
print(f"❌ Unexpected error: {e}")
# ==============================
# Test 2: Deployed Backend API
# ==============================
print("\n" + "=" * 60)
print(f"TEST 2: Calling DEPLOYED backend API for username: {USERNAME}")
print("=" * 60)
deployed_url = f"https://devhub-k9dg.onrender.com/api/linkedin/{USERNAME}/"
print(f"URL: {deployed_url}")
try:
response = requests.get(deployed_url, timeout=60)
print(f"Status Code: {response.status_code}")
try:
data = response.json()
print("\n--- Response JSON ---")
print(json.dumps(data, indent=2))
if "error" in data:
print(f"\n❌ ERROR from API: {data['error']}")
else:
print(f"\n✅ Username: {data.get('Username', 'MISSING')}")
print(f"✅ Skills count: {len(data.get('Skills', []))}")
print(f"✅ Position count: {len(data.get('Position', []))}")
print(f"✅ Education count: {len(data.get('Education', []))}")
except json.JSONDecodeError:
print(f"\n❌ Response is NOT valid JSON!")
print(f"Raw response: {response.text[:500]}")
except requests.ConnectionError:
print("❌ Could not connect to deployed backend.")
except requests.Timeout:
print("❌ Request timed out after 60 seconds")
except Exception as e:
print(f"❌ Unexpected error: {e}")
# ==============================
# Test 3: Direct RapidAPI Call
# ==============================
print("\n" + "=" * 60)
print(f"TEST 3: Calling RapidAPI DIRECTLY for username: {USERNAME}")
print("=" * 60)
rapid_url = "https://fresh-linkedin-profile-data.p.rapidapi.com/enrich-lead"
querystring = {
"linkedin_url": f"https://www.linkedin.com/in/{USERNAME}/",
"include_skills": "true",
"include_certifications": "false",
"include_publications": "false",
"include_honors": "false",
"include_volunteers": "false",
"include_projects": "false",
"include_patents": "false",
"include_courses": "false",
"include_organizations": "false",
"include_profile_status": "false",
"include_company_public_url": "false"
}
headers = {
"x-rapidapi-key": "63e87f7f8bmsh602fffeb8cef799p15e30ejsn889cc10bbe2b",
"x-rapidapi-host": "fresh-linkedin-profile-data.p.rapidapi.com",
}
print(f"LinkedIn URL: {querystring['linkedin_url']}")
try:
response = requests.get(rapid_url, headers=headers, params=querystring, timeout=30)
print(f"Status Code: {response.status_code}")
try:
data = response.json()
print("\n--- Raw RapidAPI Response ---")
print(json.dumps(data, indent=2))
# Check if data is wrapped
inner_data = data.get('data')
if inner_data:
print(f"\n✅ full_name: {inner_data.get('full_name', 'MISSING')}")
print(f"✅ headline: {inner_data.get('headline', 'MISSING')}")
print(f"✅ city: {inner_data.get('city', 'MISSING')}")
print(f"✅ skills: {inner_data.get('skills', 'MISSING')}")
print(f"✅ experiences count: {len(inner_data.get('experiences', []))}")
print(f"✅ educations count: {len(inner_data.get('educations', []))}")
else:
print(f"\n❌ No 'data' key in response! Keys: {list(data.keys())}")
except json.JSONDecodeError:
print(f"\n❌ Response is NOT valid JSON!")
print(f"Raw response: {response.text[:500]}")
except Exception as e:
print(f"❌ Error: {e}")
print("\n" + "=" * 60)
print("TEST COMPLETE")
print("=" * 60)