Search code examples
javascriptlinkedin-api

how to make request to LinkedIn API v2 and OAuth 2.0 without JS SDK?


I'm trying to integrate LinkedIn v2 OAuth 2.0 login directly from the browser, but in order to Ovid Cross-Origin issues, I need to use JS SDK.

but I saw here: https://engineering.linkedin.com/blog/2018/12/developer-program-updates

that from the 1 of March js SDK will not work

SDKs: Our JavaScript and Mobile Software Development Kits (SDKs) will stop working. Developers will need to migrate to using OAuth 2.0 directly from their apps.

so how can I make login with LinkedIn if there is no SDK any more?? (and I can't use any non-free or non-commercial OAuth lib)

and also am trying to avoid using server side for that


Solution

  • This is the solution for the V1 API. I am not sure if this will be continued or not in V2 of the API.

    You can create a URL with the parameters as follows, however there are some issues with the image and summary fields showing up as expected.

    • page - URL of Page
    • title - Page Content
    • summary - Summary of content
    • source - Name of Site

    Construct the URL as such: (interpolated string example)

    https://www.linkedin.com/shareArticle?mini=true&url=${page}&title=${title}&summary=${summary}&source=${source}

    It is recommended, if you control the html metatags to apply the following for a richer experience in sharing.

      <meta property="og:title" content="My Shared Article Title" />
      <meta property="og:description" content="Description of shared article" />
      <meta property="og:url" content="http://example.com/my_article.html" />
      <meta property="og:image" content="http://example.com/foo.jpg" />
    

    SOURCE:

    Linked In - Share on LinkedIn V1 Docs

    TypeScript Example

    This example creates a new window with the share link.

    let page = this.getPageUrl(true);
    let title = this.getTagTitle(true);
    let summary = this.getTagDescription(true);
    let source = this.getTitle(true);
    
    let tokenLink = `https://www.linkedin.com/shareArticle?mini=true&url=${page}&title=${title}&summary=${summary}&source=${source}`;
    
    window.open(tokenLink);