Download the PHP package globules-io/linkedin-php-sdk without Composer
On this page you can find all versions of the php package globules-io/linkedin-php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download globules-io/linkedin-php-sdk
More information about globules-io/linkedin-php-sdk
Files in globules-io/linkedin-php-sdk
Package linkedin-php-sdk
Short Description This package is an SDK for using LinkedIn V2 Marketing API. You can use it for managing Company Pages in this social network
License MIT
Homepage https://github.com/globules-io/linkedin-php-sdk
Informations about the package linkedin-php-sdk
LinkedIn PHP SDK
Installation
You will need at least PHP 7.4. Compatible with PHP 8.x
Use composer package manager to install the lastest version of the package:
Or add this package as dependency to composer.json
.
Get Started
Before you will get started, play visit to LinkedIn API Documentation. This will save you a lot of time and prevent some silly questions. To start working with LinkedIn API, you will need to get application client id and secret.
Go to LinkedIn Developers portal and create new application in section My Apps. Once your app has been approved, you will get a ClientId and ClientSecret, that you will use later.
LinkedIn Restrictions
The scopes or permissions aren't available right away when you register an application with LinkedIn.
When you first create your app in the developer portal, you only have access to the w_member_social
scope.
You can start developing but the token you obtain at this stage will have no refresh information.
Then you need to request access to the Marketing Developer Platform
which will give you 2 additionals scopes, r_emailaddress
, r_liteprofile
Once your request has been approved, you will get access to all the remaining scopes and your token will have refresh information.
Bootstrapping autoloader and instantiating a client
Getting local redirect URL
To start linking process you have to setup redirect url.
You can set your own or use current one.
SDK provides you a getRedirectUrl()
helper for your convenience:
We recommend you to have it stored during the linking session because you will need to use it when you will be getting access token.
Setting local redirect URL
Set a custom redirect url use:
Getting LinkedIn redirect URL
In order of performing OAUTH 2.0 flow, you should get LinkedIn login URL. During this procedure you have to define scope of requested permissions.
You can read more about Linkedin Api scopes here.
Use Scope
enum class to get scope names.
To get redirect url to LinkedIn, use the following approach:
Now you can take user to LinkedIn. You can use link or rely on Location HTTP header.
Getting Access Token
To get access token use (don't forget to set redirect url)
This method returns object of LinkedIn\AccessToken
class.
You can store this token in the file like this:
This way of storing tokens is not recommended due to security concerns and used for demonstration purpose. Please, ensure that tokens are stored securely.
Setting Access Token
You can use method setAccessToken()
for the LinkedIn\Client
class to set token stored as string. You have to pass
instance of LinkedIn\AccessToken
to this method.
Renewing Tokens
LinkedIn tokens expire after 60 days but you can renew your access token by using the refresh token. Tokens can be then refreshed for 365 days, after which the end-user must re-auth.
Performing API calls
All API calls can be called through simple method:
There are 3 helper methods:
Examples
Perform api call to get profile information
List companies where you are an admin
Get Company page profile
Setup custom API request headers
Change different headers sent to LinkedIn API.
Change default API root
Some private API access there.