Categories: JavaWeb

Java – How to Get Company Updates using LinkedIn API

This article represents code samples and changes that need to be done in original Linkedin-J framework (open-source) to get company updates of different types such as following:

  • Job Posting
  • Status Updates
  • New Product

Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos.

 

Code Samples & Steps to Get Company Updates

Following files need to be changed along with mentioned changes:

  • LinkedinApiUrls.properties: Following code needs to be added under APIs mentioned under companies:
    com.google.code.linkedinapi.client.getCompanyStatusUpdates=http://api.linkedin.com/v1/companies/{id}/updates{queryParameters}
    
  • LinkedInApiUrls.java: Following code needs to be added:
    public static final String GET_COMPANY_STATUS_UPDATES = linkedInApiUrls.getProperty("com.google.code.linkedinapi.client.getCompanyStatusUpdates");
    
  • CompaniesApiClient.java: Following APIs need to be added:
        
    /**
     * Gets the company by id.
     * 
     * @param id the id
     * 
     * @return the company by id
     */public Updates getCompanyStatusUpdates(String id);
       
        
    /**
     * Get comanpy updates by companyid and event type 
     * @param id
     * @param eventType
     * @return
     */public Updates getCompanyStatusUpdates(String id, String eventType );
    
    /**
     * Get company updates by companyid, event type, start index, count
     * @param id
     * @param eventType
     * @param start
     * @param count
     * @return
     */public Updates getCompanyStatusUpdates(String id, String eventType, int start, int count);
    
  • BaseLinkedInApiClient.java: Following implementations need to be added:
        
     @Override
     public Updates getCompanyStatusUpdates(String id) {
            assertNotNullOrEmpty("id", id);
    
            LinkedInApiUrlBuilder builder = createLinkedInApiUrlBuilder(LinkedInApiUrls.GET_COMPANY_STATUS_UPDATES);
            String                apiUrl  = builder.withEmptyField(ParameterNames.FIELD_SELECTORS).withField(ParameterNames.ID,
                     id).buildUrl();
    
            return readResponse(Updates.class, callApiMethod(apiUrl));
     }
     
            @Override
             public Updates getCompanyStatusUpdates(String id, String eventType) {
                    assertNotNullOrEmpty("id", id);
                    assertNotNullOrEmpty("eventtype", eventtype);
                    LinkedInApiUrlBuilder builder = createLinkedInApiUrlBuilder(LinkedInApiUrls.GET_COMPANY_STATUS_UPDATES);
                    String apiUrl = builder.withEmptyField(ParameterNames.FIELD_SELECTORS)
                                           .withField(ParameterNames.ID, id)
                                           .withParameter(ParameterNames.EVENT_TYPE, eventType).buildUrl();
    
                    return readResponse(Updates.class, callApiMethod(apiUrl));
             }
     
            @Override
            public Updates getCompanyStatusUpdates(String id, String eventType,
                           int start, int count) {
                    assertNotNullOrEmpty("id", id);
    
                    LinkedInApiUrlBuilder builder = createLinkedInApiUrlBuilder(LinkedInApiUrls.GET_COMPANY_STATUS_UPDATES);
                    String apiUrl = builder.withEmptyField(ParameterNames.FIELD_SELECTORS)
                                    .withField(ParameterNames.ID, id)
                                    .withParameter(ParameterNames.EVENT_TYPE, eventType)
                                    .withParameter(ParameterNames.START, String.valueOf(start))
                                    .withParameter(ParameterNames.COUNT, String.valueOf(count))
                                     .buildUrl();
    
                    return readResponse(Updates.class, callApiMethod(apiUrl));
            }
    

Once above files have been modified, you are all set to access the company status updates using following code:

public static void main(String[] args) {

        String consumerKeyValue = "your-consumer-key";
        String consumerSecretValue = "your-consumer-secret";

        String accessTokenValue = "use-your-access-token-value";
        String tokenSecretValue = "use-your-token-secret-value";

        final LinkedInApiClientFactory factory = LinkedInApiClientFactory.newInstance(consumerKeyValue, consumerSecretValue);
        final LinkedInApiClient client = factory.createLinkedInApiClient(accessTokenValue, tokenSecretValue);
 
        Updates updates = client.getCompanyStatusUpdates( "1441", "status-update", 10, 10 );
        List ulist  = updates.getUpdateList();
        if( ulist != null ) {
                Iterator uiter = ulist.iterator();
                while( uiter.hasNext() ) {
                        Update update = uiter.next();
                        CompanyStatusUpdate csu = update.getUpdateContent().getCompanyStatusUpdate();
                        if( csu != null ) {
                            System.out.println( "Status Updates: " + cssu.getShare().getComment() );
                        }
                }
        }
}

 

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking.

Recent Posts

What is Embodied AI? Explained with Examples

Artificial Intelligence (AI) has evolved significantly, from its early days of symbolic reasoning to the…

1 day ago

Retrieval Augmented Generation (RAG) & LLM: Examples

Last updated: 25th Jan, 2025 Have you ever wondered how to seamlessly integrate the vast…

3 months ago

How to Setup MEAN App with LangChain.js

Hey there! As I venture into building agentic MEAN apps with LangChain.js, I wanted to…

3 months ago

Build AI Chatbots for SAAS Using LLMs, RAG, Multi-Agent Frameworks

Software-as-a-Service (SaaS) providers have long relied on traditional chatbot solutions like AWS Lex and Google…

3 months ago

Creating a RAG Application Using LangGraph: Example Code

Retrieval-Augmented Generation (RAG) is an innovative generative AI method that combines retrieval-based search with large…

3 months ago

Building a RAG Application with LangChain: Example Code

The combination of Retrieval-Augmented Generation (RAG) and powerful language models enables the development of sophisticated…

3 months ago