LinkedIn API implementation in Your App - OAuth and Post Share.

In this part, we will see How to call a LinkedIn API and get a Linkedin OAuth Access Token and Share a post, will test using curl and postman.

In the next part, we will see how to implement that in the Go code.

 1. Get a Linkedin OAuth Access Token

Prerequisites:

LinkedIn Account

curl


1. Client Registration


go to: 

https://www.linkedin.com/developers/apps


Click on "create new" or use this direct link:

https://www.linkedin.com/developers/apps/new


Verify Company










What you need:


redirectURI = 

URLENCODE(redirectURI) = 

clientId = 

clientSecret = 


clientID = 78.................vl

clientSecret = I2.................n9kW
redirectURI = https://www.google.com/


URLENCODE (redirectURI) = https%3A%2F%2Fwww.google.com%2F (URLENCODE part of url for curl param) encode using (https://www.urlencoder.org/)



Authorization Endpoint (Browser)


What you need:

scope = r_liteprofile


“https://www.linkedin.com/oauth/v2/authorization?response_type=code&state=987654321&scope=scope&client_id=clientId&redirect_uri=URLENCODE(redirectURI)”
Paste into Browser

Will Redirect to login

Ask for permission

What you need from the response:

code =


Redirect with code 
code=AQRumXrI1yM5hbKqMLOfitdv7-T3QCndn4Rwo7BEUbYla5b6j14H2kH858-CUCUtk3h_9cm_Zt95fRRsH_iqOL3GpWLfZ8T2et5bcD59_dO0FKGTjjuYsoJ-_uqrO6r...............................Yrciht7k7gtwnojLPeQzw

Token Endpoint:


curl -ik -X POST https://www.linkedin.com/oauth/v2/accessToken \

-d grant_type=authorization_code \

-d code=code \

-d redirect_uri=URLENCODE(redirectURI) \

-d client_id=clientId \

-d client_secret=clientSecret


Values :- 


curl -ik -X POST https://www.linkedin.com/oauth/v2/accessToken \

-d grant_type=authorization_code \

-d code=AQRumXrI1yM5hbKqML.........................................Yrciht7k7gtwnojLPeQzw \

-d redirect_uri=https%3A%2F%2Fwww.google.com%2F \

-d client_id=78...........yykkvl \

-d client_secret=I28N...............9kW


Paste it on terminal

What you need from the response:

access_token =






access_token=AQX................HwQsHxBDFO3gZw-CH9wpYfb62TEVp5f6_ThlzwAc0kJ5sZvmT-nayYw6mfPYAY7lkh3INTxJl9................6No_rgqmpmwZH5XB3S3LJm1Y9KN-MRtLUZvirqyU8ydoKm75j8-m2am1nRjFpFR71XO9h..............83Vwlt4W9eyr4dgNEMXwD9_XVwPc_B9VnPo40MG9evJ5MBzJWZg3qCUUXu43i1_tkcJDPrQvdFSkGwHd732FO6...........QMjndilBHkgx_EZuyXh7dfIMdyJZ5e7XIJI-uX...............64F_GkB5vZHPZdPf_qug


Resource Access:


curl https://api.linkedin.com/v2/me -H "Authorization: Bearer access_token"



curl https://api.linkedin.com/v2/me -H "Authorization: Bearer AQXN9593lxHbXQAXIoYJNH...........CH9wpYfb62TEVp5f6_ThlzwAc0kJ5sZvmT-nayYw6mfPYAY7lkh3IN.............Z98-o6No_rgqmpmwZH5XB3S3LJm1Y9KN-MRtLUZvirqyU8ydoKm75j8-m2am1nRjFpFR71XO9hdPU................._B9VnPo40MG9evJ5MBzJWZg3qCUUXu43i1_tkcJDPrQvdFSkGwHd732FO6..........dilBHkgx_EZuyXh7dfIMdyJZ5e7X............F_GkB5vZHPZdPf_qug"


What you need from the response:

firstname =



2. Post Shares


Your application may post shares in the context of a specific member or organization. Use a URN in the owner field to associate the share with an organization or authenticated member. The valid URN formats are urn:li:person:{id} or urn:li:organization:{id}.

You will need the permission w_member_social to create shares on behalf of a member, or w_organization_social to create shares on behalf of an organization.

1) Default Application Permissions:

  • r_liteprofile

  • rw_company_admin

  • w_member_social

2) Under OAuth 2.0, Authorized Redirect URLs, add:

3) Copy the Authentication Keys:

  • Client ID

  • Client Secret

 

1) Open PostMan and import file:

  • linkedin.postman_collection.json

2) Edit collection LinkedIn:

  • Click Authorization

  • Click Get New Access Token

3) Fill the following:


4) Click on Request Token

5) You will be redirected to LinkedIn page

6) Click on Use Token

7) Click on Update

Retrieve Person URN

1) Choose Retrieve author

2) Copy value for key "id"

Create a share

1) Choose Create an Article or URL Share

2) Edit Body

For submitting a fully described share via POST:

{

    "author": "urn:li:person:{{person_id}}",

    "lifecycleState": "PUBLISHED",

    "specificContent": {

        "com.linkedin.ugc.ShareContent": {

            "shareCommentary": {

                "text": ""

            },

            "shareMediaCategory": "ARTICLE",

            "media": [

                {

                    "status": "READY",

                    "description": {

                        "text": ""

                    },

                    "originalUrl": "",

                    "title": {

                        "text": ""

                    }

                }

            ]

        }

    },

    "visibility": {

        "com.linkedin.ugc.MemberNetworkVisibility": "CONNECTIONS"

    }

}


3) Replace {{person_id}} with Person URN (paste previously copied value)

4) com.linkedin.ugc. MemberNetworkVisibility can be:

  • CONNECTIONS - Represents 1st degree network of owner.

  • PUBLIC - Anyone can view this.

  • LOGGED_IN - Viewable by logged in members only.

5) Click on Send




Comments

Post a Comment

Popular posts from this blog

Golang Interview Questions Part 1 Theory Top 50 Question

Complete Golang Development setup on Linux (Ubuntu 20.04 )

Best GitHub repositories for Go