Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getToken() Error ? #59

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
eaa09f0
Add New refresh token parameters
samoritano Aug 27, 2020
832bfe5
Add method for renewing token from refresh token
samoritano Aug 27, 2020
f806872
Restore v2 api URL
samoritano Aug 27, 2020
5030acd
Extract validateResponse methods for codeclimate
samoritano Aug 28, 2020
210f8f8
Updating composer.json description
samoritano Sep 26, 2020
38db9b1
Ignore whole .idea folder
samoritano Sep 26, 2020
402aad8
Remove russian Readme (sorry, zoonman!)
samoritano Sep 26, 2020
8e5e3b7
Update composer links
samoritano Sep 26, 2020
975e317
Update README
samoritano Sep 26, 2020
2d25a96
Modify author in composer.json
samoritano Sep 26, 2020
ff9d6d1
Update README file
samoritano Jan 14, 2021
8574cd9
Bump Guzzle to v7
samoritano Jan 14, 2021
67c95b7
added parameter raw data for query tunneling
ccorreia64 Jan 18, 2021
df7758a
Refactor query tunneling
ccorreia64 Jan 27, 2021
5413aa6
revert to guzzle v6
ccorreia64 Jan 28, 2021
a666352
fix response for empty body
n-gibs Oct 12, 2021
58491a3
update repo name
n-gibs Oct 26, 2021
c98c23f
fix package name
n-gibs Oct 26, 2021
b772718
fix readme
n-gibs Oct 26, 2021
c60f295
php8 and guzzle update
n-gibs Dec 1, 2021
e255cd9
remove unused files
n-gibs Dec 1, 2021
5ebddd7
remove travis file
n-gibs Dec 1, 2021
0568a98
remove code of conduct and edit readme
n-gibs Dec 1, 2021
66ce56b
Merge pull request #1 from AgencyPMG/php8-support
n-gibs Dec 1, 2021
4360425
Merge pull request #1 from AgencyPMG/master
samoritano Apr 21, 2022
c265268
fix: Proper composer command
podarok Sep 16, 2022
0574ebf
Merge pull request #2 from podarok/patch-1
samoritano Jan 21, 2023
e44e8f4
Use Query::build
esensgit Apr 14, 2023
59f36db
Update composer.json
esensgit Apr 14, 2023
9cd91f6
Update README.md
esensgit Apr 14, 2023
9f0d22b
Update README.md
esensgit Apr 14, 2023
ffe18dc
Removed validation of refresh data.
esensgit Apr 14, 2023
992dc56
Update AccessToken.php
esensgit Apr 14, 2023
3118bdf
Update AccessToken.php
esensgit Apr 18, 2023
08e522d
Update AccessToken.php
esensgit Apr 18, 2023
7ba21a9
Update README.md
esensgit Apr 19, 2023
440ba82
-- using Query::class insted of build_query()
jerry4rahul Aug 21, 2023
01aee49
Merge pull request #3 from esensgit/master
samoritano Nov 23, 2023
47ed031
Update readme
samoritano Dec 9, 2023
6e9666f
Merge pull request #4 from jerry4rahul/master
samoritano Dec 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/gradle.xml
.idea/**/libraries
.idea/**/mongoSettings.xml
.idea/*
*.iws
/out/
.idea_modules/
Expand Down
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

46 changes: 0 additions & 46 deletions CODE_OF_CONDUCT.md

This file was deleted.

4 changes: 0 additions & 4 deletions CONTRIBUTING.md

This file was deleted.

6 changes: 0 additions & 6 deletions ISSUE_TEMPLATE.md

This file was deleted.

21 changes: 0 additions & 21 deletions LICENSE.md

This file was deleted.

149 changes: 23 additions & 126 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
LinkedIn API Client with OAuth 2 authorization written on PHP
============================================================
[![Build Status](https://travis-ci.org/zoonman/linkedin-api-php-client.svg?branch=master)](https://travis-ci.org/zoonman/linkedin-api-php-client) [![Code Climate](https://codeclimate.com/github/zoonman/linkedin-api-php-client/badges/gpa.svg)](https://codeclimate.com/github/zoonman/linkedin-api-php-client) [![Packagist](https://img.shields.io/packagist/dt/zoonman/linkedin-api-php-client.svg)](https://packagist.org/packages/zoonman/linkedin-api-php-client) [![GitHub license](https://img.shields.io/github/license/zoonman/linkedin-api-php-client.svg)](https://github.com/zoonman/linkedin-api-php-client/blob/master/LICENSE.md)



See [complete example](examples/) inside [index.php](examples/index.php) to get started.


## Installation

You will need at least PHP 7.3. We match [officially supported](https://www.php.net/supported-versions.php) versions of PHP.
You will need at least PHP 7.4. We match [officially supported](https://www.php.net/supported-versions.php) versions of PHP.

Use [composer](https://getcomposer.org/) package manager to install the lastest version of the package:

```bash
composer require zoonman/linkedin-api-php-client
composer require samoritano/linkedin-api-php-client
```

Or add this package as dependency to `composer.json`.

If you have never used Composer, you should start [here](http://www.phptherightway.com/#composer_and_packagist)
and install composer.


## Get Started

Before you will get started, play visit to [LinkedIn API Documentation](https://docs.microsoft.com/en-us/linkedin/).
Before you will get started, play visit to [LinkedIn API Documentation](https://docs.microsoft.com/en-us/linkedin/marketing/getting-started).
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.
To start working with LinkedIn API, you will need to
get application client id and secret.

Go to [LinkedIn Developers portal](https://developer.linkedin.com/)
and create new application in section My Apps.
Save ClientId and ClientSecret, you will use them later.
Go to [LinkedIn Developers portal](https://www.linkedin.com/developers/)
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.


#### Bootstrapping autoloader and instantiating a client
Expand All @@ -55,29 +46,32 @@ $client = new Client(

#### Getting local redirect URL

To start linking process you have to setup 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:

```php
$redirectUrl = $client->getRedirectUrl();
```

We recommend you to have it stored during the linking session
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
#### Setting local redirect URL

Set a custom redirect url use:

```php
$client->setRedirectUrl('http://your.domain.tld/path/to/script/');
```

#### Getting LinkedIn redirect URL
#### 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](https://docs.microsoft.com/en-us/linkedin/shared/references/migrations/default-scopes-migration).

Use `Scope` enum class to get scope names.
To get redirect url to LinkedIn, use the following approach:

Expand All @@ -86,7 +80,7 @@ use LinkedIn\Scope;

// define scope
$scopes = [
Scope::READ_LITE_PROFILE,
Scope::READ_LITE_PROFILE,
Scope::READ_EMAIL_ADDRESS,
Scope::SHARE_AS_USER,
Scope::SHARE_AS_ORGANIZATION,
Expand All @@ -96,20 +90,20 @@ $loginUrl = $client->getLoginUrl($scopes); // get url on LinkedIn to start linki

Now you can take user to LinkedIn. You can use link or rely on Location HTTP header.

#### Getting Access Token
#### Getting Access Token

To get access token use (don't forget to set redirect url)

```php
$accessToken = $client->getAccessToken($_GET['code']);
```
This method returns object of `LinkedIn\AccessToken` class.
This method returns object of `LinkedIn\AccessToken` class.
You can store this token in the file like this:
```php
file_put_contents('token.json', json_encode($accessToken));
```
This way of storing tokens is not recommended due to security concerns and used for demonstration purpose.
Please, ensure that tokens are stored securely.
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

Expand All @@ -122,7 +116,7 @@ use LinkedIn\Client;

// instantiate the Linkedin client
$client = new Client(
'LINKEDIN_APP_CLIENT_ID',
'LINKEDIN_APP_CLIENT_ID',
'LINKEDIN_APP_CLIENT_SECRET'
);

Expand All @@ -136,7 +130,7 @@ $accessToken = new AccessToken($tokenData['token'], $tokenData['expiresAt']);
$client->setAccessToken($accessToken);
```

#### Performing API calls
#### Performing API calls

All API calls can be called through simple method:

Expand Down Expand Up @@ -177,49 +171,13 @@ print_r($profile);

```php
$profile = $client->get(
'organizations',
['is-company-admin' => true]
'organizationalEntityAcls',
['q' => 'roleAssignee']
);
print_r($profile);
```

##### Share content on a personal profile

Make sure that image URL is available from the Internet (don't use localhost in the image url).

```php
$share = $client->post(
'ugcPosts',
[
'author' => 'urn:li:person:' . $profile['id'],
'lifecycleState' => 'PUBLISHED',
'specificContent' => [
'com.linkedin.ugc.ShareContent' => [
'shareCommentary' => [
'text' => 'Checkout this amazing PHP SDK for LinkedIn!'
],
'shareMediaCategory' => 'ARTICLE',
'media' => [
[
'status' => 'READY',
'description' => [
'text' => 'OAuth 2 flow, composer Package.'
],
'originalUrl' => 'https://github.com/zoonman/linkedin-api-php-client',
'title' => [
'text' => 'PHP Client for LinkedIn API'
]
]
]
]
],
'visibility' => [
'com.linkedin.ugc.MemberNetworkVisibility' => 'CONNECTIONS'
]
]
);
print_r($share);
```

##### Get Company page profile

Expand All @@ -229,46 +187,7 @@ $companyInfo = $client->get('organizations/' . $companyId);
print_r($companyInfo);
```

##### Share content on a LinkedIn business page

```php
// set sandboxed company page to work with
// you can check updates at
// https://www.linkedin.com/company/devtestco
$companyId = '2414183';

$share = $client->post(
'ugcPosts',
[
'author' => 'urn:li:organization:' . $companyId,
'lifecycleState' => 'PUBLISHED',
'specificContent' => [
'com.linkedin.ugc.ShareContent' => [
'shareCommentary' => [
'text' => 'Checkout this amazing PHP SDK for LinkedIn!'
],
'shareMediaCategory' => 'ARTICLE',
'media' => [
[
'status' => 'READY',
'description' => [
'text' => 'OAuth 2 flow, composer Package.'
],
'originalUrl' => 'https://github.com/zoonman/linkedin-api-php-client',
'title' => [
'text' => 'PHP Client for LinkedIn API'
]
]
]
]
],
'visibility' => [
'com.linkedin.ugc.MemberNetworkVisibility' => 'PUBLIC'
]
]
);
print_r($share);
```

##### Setup custom API request headers

Expand All @@ -290,25 +209,3 @@ Some private API access there.
```php
$client->setApiRoot('https://api.linkedin.com/v2/');
```

##### ~Image Upload~

I assume you have to be LinkedIn partner or something like that.

Try to upload image to LinkedIn. See [Rich Media Shares](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/rich-media-shares)
(returns "Not enough permissions to access media resource" for me).

```php
$filename = '/path/to/image.jpg';
$client->setApiRoot('https://api.linkedin.com/');
$mp = $client->upload($filename);
```

## Contributing

Please, open PR with your changes linked to an GitHub issue.
You code must follow [PSR](http://www.php-fig.org/psr/) standards and have PHPUnit tests.

## License

[MIT](LICENSE.md)
Loading