How to Get Latest Linkedin Posts or Activities with an API ? [2024]

How to Get Latest Linkedin Posts or Activities with an API ? [2024]

In the fast-paced world of professional networking, staying updated with the latest activities/posts on LinkedIn can be a crucial aspect for many businesses and individuals. As a developer, leveraging Piloterr's API to access these activities not only keeps you informed but also opens up a plethora of opportunities for data analysis, trend monitoring, and targeted networking. In this comprehensive guide, we'll dive into how to harness the Piloterr API to fetch the most recent activities.

The script we're sharing with you describes a method for retrieving LinkedIn activities matching specific keywords or hashtags, using the APIs provided by Piloterr.

How to run the code?

  1. Copy the code
  2. Create a new file‍
  3. Replace the API token with your own
  4. Replace QUERY with your sector, a business topic or any other subject you wish to analyze
  5. Run the script with py
import requests

QUERY = 'Formation'

def get_linkedin_post_details(known_url: str):
    api_url = ""
    headers = {
        "x-api-key": PILOTERR_API_KEY
    params = {
        "query": known_url
    response = requests.get(
    if response.status_code == 200:
        return response.json()
        return "Error: Unable to fetch data"

def get_linkedin_post_url_from_google(query: str):
    google_api_url = ""
    headers = {
        "x-api-key": PILOTERR_API_KEY
    data = {
        "query": query
    response =

    if response.status_code == 200:
        search_results = response.json()['organic_results']

        # Extract LinkedIn URL from search results
        for result in search_results:
            if '' in result['link']:
        return "LinkedIn URL not found in search results"
        return "Error: Unable to perform search"

# Example usage
posts = []
search_query = f" inurl:posts after:2023-01-01 besoin AROUND(5) {QUERY}"
linkedin_url = get_linkedin_post_url_from_google(search_query)

print(f"Count of LinkedIn posts found: {len(posts)}. Fetching details...")

parsed_posts = []

for p in posts:
    get_post_details = get_linkedin_post_details(p)


Here's a description of how the script works

1. Extracting LinkedIn Posts Using Google Search

The script uses a search query with specific parameters to find LinkedIn posts via Google Search. This is achieved using the Piloterr API for Google search.

It employs search operators like site:, inurl:, after:, and AROUND() to refine the search to specific LinkedIn posts containing the desired keywords within a certain date range.

2. Collecting Post Details from LinkedIn

Once the URLs of LinkedIn posts are obtained from Google Search results, the script uses another Piloterr API : Linkedin Post Info to fetch detailed information about each post.

This information can include the content of the post, author details, number of comments, likes, etc.

3. Script Execution:

  1. The script initializes an empty list posts to store the URLs of LinkedIn posts.
  2. It then forms a search query incorporating the desired keywords and search parameters.
  3. After obtaining the URLs, the script fetches details for each post and stores them in parsed_posts.


    "id": "7043937317610287104",
    "url": "",
    "text": "I strongly believe that employees’ know-how is the company's most...",
    "author": {
      "url": "",
      "full_name": "Najette Fellache 🔆",
      "image_url": "",
      "profile_type": "person"
    "hashtags": [],
    "image_url": "",
    "like_count": 125,
    "comments_count": 4,
    "date_published": "2023-03-21T13:32:06.530Z",
    "total_engagement": 129,
    "mentioned_profiles": []


The article explains how using specific keywords to search and analyze LinkedIn activities can be a powerful tool. This method helps in tracking trends, analyzing data, and improving networking. It keeps users up-to-date in their industry and supports strategic growth in the digital world.