Skip to content

Commit f803aea

Browse files
committed
Update examples
1 parent e8cca49 commit f803aea

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

examples/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,8 @@ php -S localhost:8901 -t examples
4545
```
4646

4747
Navigate to http://localhost:8901/
48+
49+
If you will see error like `Class 'Dotenv\Dotenv' not found...` install DotEnv using the following command:
50+
```bash
51+
composer require vlucas/phpdotenv
52+
```

examples/index.php

+23-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
$client->setRedirectUrl($_SESSION['redirect_url']);
5454
// retrieve access token using code provided by LinkedIn
5555
$accessToken = $client->getAccessToken($_GET['code']);
56-
echo 'Access token:';
56+
h1('Access token');
5757
pp($accessToken); // print the access token content
58-
echo 'Profile:';
58+
h1('Profile');
5959
// perform api call to get profile information
6060
$profile = $client->get(
6161
'people/~:(id,email-address,first-name,last-name)'
@@ -83,6 +83,11 @@
8383
// https://www.linkedin.com/company/devtestco
8484
$companyId = '2414183';
8585

86+
h1('Company information');
87+
$companyInfo = $client->get('companies/' . $companyId . ':(id,name,num-followers,description)');
88+
pp($companyInfo);
89+
90+
h1('Sharing on company page');
8691
$companyShare = $client->post(
8792
'companies/' . $companyId . '/shares',
8893
[
@@ -104,6 +109,7 @@
104109
]
105110
);
106111
pp($companyShare);
112+
107113

108114
/*
109115
// Returns {"serviceErrorCode":100,"message":"Not enough permissions to access media resource","status":403}
@@ -135,7 +141,12 @@
135141
echo '<a href="/">Start over</a>';
136142
} else {
137143
// define desired list of scopes
138-
$scopes = Scope::getValues();
144+
$scopes = [
145+
Scope::READ_BASIC_PROFILE,
146+
Scope::READ_EMAIL_ADDRESS,
147+
Scope::MANAGE_COMPANY,
148+
Scope::SHARING,
149+
];
139150
$loginUrl = $client->getLoginUrl($scopes); // get url on LinkedIn to start linking
140151
$_SESSION['state'] = $client->getState(); // save state for future validation
141152
$_SESSION['redirect_url'] = $client->getRedirectUrl(); // save redirect url for future validation
@@ -151,3 +162,12 @@ function pp($anything)
151162
{
152163
echo '<pre>' . print_r($anything, true) . '</pre>';
153164
}
165+
166+
/**
167+
* Add header
168+
*
169+
* @param string $h
170+
*/
171+
function h1($h) {
172+
echo '<h1>' . $h . '</h1>';
173+
}

0 commit comments

Comments
 (0)