55[ ![ Latest Stable Version] ( https://poser.pugx.org/elninotech/linkedin-api-client/v )] ( https://packagist.org/packages/elninotech/linkedin-api-client )
66[ ![ Total Downloads] ( https://poser.pugx.org/elninotech/linkedin-api-client/downloads )] ( https://packagist.org/packages/elninotech/linkedin-api-client/stats )
77
8-
98A PHP library to handle authentication and communication with LinkedIn API. The library/SDK helps you to get an access
109token and when authenticated it helps you to send API requests. You will not get * everything* for free though... You
11- have to read the [ LinkedIn documentation] [ api-doc-core ] to understand how you should query the API.
10+ have to read the [ LinkedIn documentation] [ api-doc-core ] to understand how you should query the API.
1211
1312To get an overview what this library actually is doing for you. Take a look at the authentication page from
1413the [ API docs] [ api-doc-authentication ] .
@@ -19,55 +18,27 @@ Here is a list of features that might convince you to choose this LinkedIn clien
1918
2019* Flexible and easy to extend
2120* Developed with modern PHP standards
22- * Not developed for a specific framework.
21+ * Not developed for a specific framework.
2322* Handles the authentication process
2423* Respects the CSRF protection
2524
2625## Installation
2726
28- ** TL;DR**
29- ``` bash
30- composer require php-http/curl-client guzzlehttp/psr7 php-http/message elninotech/linkedin-api-client
31- ```
32-
33- This library does not have a dependency on Guzzle or any other library that sends HTTP requests. We use the awesome
34- HTTPlug to achieve the decoupling. We want you to choose what library to use for sending HTTP requests. Consult this list
35- of packages that support [ php-http/client-implementation] ( https://packagist.org/providers/php-http/client-implementation )
36- find clients to use. For more information about virtual packages please refer to
37- [ HTTPlug] ( http://docs.php-http.org/en/latest/httplug/users.html ) . Example:
38-
39- ``` bash
40- composer require php-http/guzzle7-adapter
41- ```
42-
43- You do also need to install a PSR-7 implementation and a factory to create PSR-7 messages (PSR-17 whenever that is
44- released). You could use Guzzles PSR-7 implementation and factories from php-http:
27+ First, install Linkedin-API-client via the [ Composer] [ composer ] package manager:
4528
4629``` bash
47- composer require guzzlehttp/psr7 php-http/message
30+ composer require elninotech/linkedin-api-client
4831```
4932
50- Now you may install the library by running the following:
33+ Ensure that the ` php-http/discovery ` composer plugin is allowed to run or install a client manually if your project does
34+ not already have a PSR-18 client integrated.
5135
5236``` bash
53- composer require elninotech/linkedin-api-client
37+ composer require guzzlehttp/guzzle
5438```
5539
5640If you are updating from a previous version, make sure to read [ the upgrade documentation] ( Upgrade.md ) .
5741
58- ### Finding the HTTP client (optional)
59-
60- The LinkedIn client needs to know what library you are using to send HTTP messages. You could provide an instance of
61- HttpClient and MessageFactory or you could fall back to auto discovery. Below is an example of where you provide a Guzzle7
62- instance.
63-
64- ``` php
65- $linkedIn=new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret');
66- $linkedIn->setHttpClient(new \Http\Adapter\Guzzle7\Client());
67- $linkedIn->setHttpMessageFactory(new Http\Message\MessageFactory\GuzzleMessageFactory());
68-
69- ```
70-
7142## Usage
7243
7344In order to use this API client (or any other LinkedIn clients), you have to [ register your application] [ register-app ]
@@ -91,7 +62,7 @@ This example below is showing how to login with LinkedIn.
9162 */
9263//require_once "vendor/autoload.php";
9364
94- $linkedIn= new Elnino\LinkedIn\LinkedIn('client_id', 'client_secret');
65+ $linkedIn = new Elnino\LinkedIn\LinkedIn('client_id', 'client_secret');
9566
9667if ($linkedIn->isAuthenticated()) {
9768 //we know that the user is authenticated now. Start query the API
@@ -112,10 +83,10 @@ echo "<a href='$url'>Login with LinkedIn</a>";
11283
11384### How to post on LinkedIn wall
11485
115- The example below shows how you can post on a users wall. The access token is fetched from the database.
86+ The example below shows how you can post on a users wall. The access token is fetched from the database.
11687
11788``` php
118- $linkedIn= new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret');
89+ $linkedIn = new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret');
11990$linkedIn->setAccessToken('access_token_from_db');
12091
12192$options = array('json'=>
@@ -142,15 +113,15 @@ var_dump($result);
142113
143114### The api options
144115
145- The third parameter of ` LinkedIn::api ` is an array with options. Below is a table of array keys that you may use.
116+ The third parameter of ` LinkedIn::api ` is an array with options. Below is a table of array keys that you may use.
146117
147- | Option name | Description
148- | ----------- | -----------
149- | body | The body of a HTTP request. Put your json string here.
150- | headers | This is HTTP headers to the request
151- | json | This is an array with json data that will be encoded to a json string.
152- | response_data_type | To override the response format for one request
153- | query | This is an array with query parameters
118+ | Option name | Description
119+ |--------------------|------------------------------------------------------------- -----------
120+ | body | The body of a HTTP request. Put your json string here.
121+ | headers | This is HTTP headers to the request
122+ | json | This is an array with json data that will be encoded to a json string.
123+ | response_data_type | To override the response format for one request
124+ | query | This is an array with query parameters
154125
155126### Understanding response data type
156127
@@ -159,7 +130,7 @@ The data type returned from `LinkedIn::api` can be configured. You may use the t
159130
160131``` php
161132// By constructor argument
162- $linkedIn= new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret', 'array');
133+ $linkedIn = new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret', 'array');
163134
164135// By setter
165136$linkedIn->setResponseDataType('string');
@@ -171,29 +142,29 @@ $linkedIn->get('/v2/me/?projection=(id,firstName,lastName)', array('response_dat
171142
172143Below is a table that specifies what the possible return data types are when you call ` LinkedIn::api ` .
173144
174- | Type | Description
175- | ------ | ------------
176- | array | An assosiative array. This can only be used with the ` json ` format.
177- | psr7 | A PSR7 response.
178- | stream | A file stream.
179- | string | A plain old string.
180-
145+ | Type | Description
146+ |--------|---------------------------------------------------------------------
147+ | array | An assosiative array. This can only be used with the ` json ` format.
148+ | psr7 | A PSR7 response.
149+ | stream | A file stream.
150+ | string | A plain old string.
181151
182152### Use different Session classes
183153
184154You might want to use another storage than the default ` SessionStorage ` . If you are using Laravel
185- you are more likely to inject the ` IlluminateSessionStorage ` .
155+ you are more likely to inject the ` IlluminateSessionStorage ` .
156+
186157``` php
187- $linkedIn= new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret');
158+ $linkedIn = new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret');
188159$linkedIn->setStorage(new IlluminateSessionStorage());
189160```
190161
191162You can inject any class implementing ` DataStorageInterface ` . You can also inject different ` UrlGenerator ` classes.
192163
193164### Using different scopes
194165
195- If you want to define special scopes when you authenticate the user you should specify them when you are generating the
196- login url. If you don't specify scopes LinkedIn will use the default scopes that you have configured for the app.
166+ If you want to define special scopes when you authenticate the user you should specify them when you are generating the
167+ login url. If you don't specify scopes LinkedIn will use the default scopes that you have configured for the app.
197168
198169``` php
199170$scope = 'r_fullprofile,r_emailaddress,w_share';
@@ -204,11 +175,26 @@ $url = $linkedIn->getLoginUrl(array('scope'=>$scope));
204175echo "<a href =' $url' >Login with LinkedIn</a >";
205176```
206177
178+ ### Using a different http client
179+
180+ If you want to customize how the requests are being sent, you can inject a different ` RequestManager ` when instantiating
181+ the API.
182+
183+ ``` php
184+ $myRequestManager = new MySpecialRequestManager();
185+ $linkedIn = new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret', 'array', $myRequestManager);
186+ ```
187+
207188### Special thanks
208189
209190This repo was originally created by [ Thomas Nyholm from Happyr] [ forked-from ] .
210191
192+ [ composer ] : https://getcomposer.org/
193+
211194[ register-app ] : https://www.linkedin.com/developers/apps
195+
212196[ api-doc-authentication ] : https://learn.microsoft.com/en-us/linkedin/shared/authentication/authentication
197+
213198[ api-doc-core ] : https://learn.microsoft.com/en-us/linkedin/shared/api-guide/concepts
199+
214200[ forked-from ] : https://github.com/Happyr/LinkedIn-API-client
0 commit comments