// Set the search term
$search_term = 'John Smith';
// Set the LinkedIn API endpoint and parameters
$url = "https://api.linkedin.com/v2/people?q=".urlencode($search_term)."&projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))";
$headers = [
"Authorization: Bearer YOUR_ACCESS_TOKEN",
"Connection: Keep-Alive"
];
// Initialize cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute the request and get the response
$response = curl_exec($ch);
curl_close($ch);
// Decode the JSON response
$data = json_decode($response, true);
// Print the results
foreach ($data['elements'] as $person) {
echo $person['firstName'].' '.$person['lastName'].'<br>';
}
GET https://api.linkedin.com/v2/people?q=<SEARCH_TERM>&projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))
import requests
search_term = 'John Smith'
access_token = 'YOUR_ACCESS_TOKEN'
url = f'https://api.linkedin.com/v2/people?q={search_term}&projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))'
headers = {'Authorization': f'Bearer {access_token}'}
response = requests.get(url, headers=headers)
data = response.json()
# Print the results
for person in data['elements']:
print(f"{person['firstName']} {person['lastName']}")
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
public class LinkedInSearch {
public static void main(String[] args) throws IOException {
// Set the search term
String searchTerm = "John Smith";
String encodedSearchTerm = URLEncoder.encode(searchTerm, "UTF-8");
// Set the LinkedIn API endpoint and parameters
String url = "https://api.linkedin.com/v2/people?q=" + encodedSearchTerm + "&projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))";
// Set the LinkedIn API access token
String accessToken = "YOUR_ACCESS_TOKEN";
// Set the HTTP headers
String authorizationHeader = "Bearer " + accessToken;
String connectionHeader = "Keep-Alive";
// Create the HTTP client and request
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader(HttpHeaders.AUTHORIZATION, authorizationHeader);
httpGet.addHeader(HttpHeaders.CONNECTION, connectionHeader);
// Execute the request and get the response
HttpResponse response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
// Parse the JSON response
ObjectMapper objectMapper = new ObjectMapper();
InputStream inputStream = entity.getContent();
LinkedInSearchResult result = objectMapper.readValue(inputStream, LinkedInSearchResult.class);
// Print the results
for (LinkedInPerson person : result.getElements()) {
System.out.println(person.getFirstName() + " " + person.getLastName());
}
// Close the HTTP client and release the connection
EntityUtils.consume(entity);
httpClient.close();
}
}
class LinkedInSearchResult {
private LinkedInPerson[] elements;
public LinkedInPerson[] getElements() { return elements; }
public void setElements(LinkedInPerson[] elements) { this.elements = elements; }
}
class LinkedInPerson {
private String firstName;
private String lastName;
public String getFirstName() { return firstName; }
public void setFirstName(String firstName) { this.firstName = firstName; }
public String getLastName() { return lastName; }
public void setLastName(String lastName) { this.lastName = lastName; }
}