In Previous blog Click Here We also learned that How to Sign-in or login from PHP 7 using LinkedIn API. So, In this blog, I am going to post or send form data from PHP using Linkedin API. In the previous blog, I already Install βcomposer require guzzlehttp/guzzle:^7.0β and create a Linkedin API and Sign In & Login from Linkedin API. So, Letβs start to describe In this blog I am creating a page βprofile.phpβ for after Login in Linkedin so return in βprofile.phpβ like Mention below-
<?php | |
require "config.php"; | |
$profile = $linkedin->getPerson($_SESSION['linkedInAccessToken']); | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Share with LinkedIn API v2</title> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> | |
<style> | |
body, html { | |
height: 100%; | |
} | |
.bg { | |
background-image: url("/images/bg.jpg"); | |
height: 100%; | |
background-position: center; | |
background-repeat: no-repeat; | |
background-size: cover; | |
} | |
</style> | |
</head> | |
<body class="bg"> | |
<div class="container"> | |
<br><br><br> | |
<div class="row"> | |
<div class="col-6 offset-3" style="margin: auto;background: white; padding: 20px; box-shadow: 10px 10px 5px #888;"> | |
<div class="panel-heading"> | |
<h1>Share on LinkedIn</h1> | |
<p style="font-style: italic;">Profile</p> | |
</div> | |
<hr> | |
<div class="panel-body"> | |
<div class="row"> | |
<div class="col-3"> | |
<img src="<?php echo $profile->profilePicture->{"displayImage~"}->elements[0]->identifiers[0]->identifier; ?>" alt="" class="thumbnail"> | |
</div> | |
<div class="col-9"> | |
<dl class="row"> | |
<dt class="col-12"> | |
Profile ID | |
</dt> | |
<dd class="col-12"> | |
<?php echo $profile->id ?> | |
</dd> | |
<dt class="col-12"> | |
Profile Name | |
</dt> | |
<dd class="col-12"> | |
<?php echo $profile->firstName->localized->en_US ?> <?php echo $profile->lastName->localized->en_US ?> | |
</dd> | |
</dl> | |
</div> | |
</div> | |
<hr> | |
<h5>Share Post</h5> | |
<form action="redirector.php"> | |
<select name="type" id="type" class="form-control" required="required"> | |
<option value="text">Share Text Post</option> | |
</select> | |
<br> | |
<input type="submit" class="btn btn-danger btn-block" value="Proceed"> | |
</form> | |
</div> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
Output-

When you click to proceed button for then βredirector.phpβ and re-director page will return you in βgettextpost.phpβ mention below-
<?php | |
$type = $_GET['type']; | |
switch ($type) { | |
case 'text': | |
header("location: /gettextpost.php"); | |
die(); | |
break; | |
default: | |
die("INVALID USE OF HEADER INFORMATION"); | |
break; | |
} |
After click Share button for Post the redirect to βgettextpost.phpβ so this page data mention below-
<?php | |
require "config.php"; | |
$profile = $linkedin->getPerson($_SESSION['linkedInAccessToken']); | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Share with LinkedIn API v2</title> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> | |
<style> | |
body, html { | |
height: 100%; | |
} | |
.bg { | |
background-image: url("/images/bg.jpg"); | |
height: 100%; | |
background-position: center; | |
background-repeat: no-repeat; | |
background-size: cover; | |
} | |
</style> | |
</head> | |
<body class="bg"> | |
<div class="container"> | |
<br><br><br> | |
<div class="row"> | |
<div class="col-6 offset-3" style="margin: auto;background: white; padding: 20px; box-shadow: 10px 10px 5px #888;"> | |
<div class="panel-heading"> | |
<h1>Share on LinkedIn</h1> | |
<p style="font-style: italic;">Profile</p> | |
</div> | |
<hr> | |
<div class="panel-body"> | |
<div class="row"> | |
<div class="col-3"> | |
<img src="<?php echo $profile->profilePicture->{"displayImage~"}->elements[0]->identifiers[0]->identifier; ?>" alt="" class="thumbnail"> | |
</div> | |
<div class="col-9"> | |
<dl class="row"> | |
<dt class="col-12"> | |
Profile ID | |
</dt> | |
<dd class="col-12"> | |
<?php echo $profile->id ?> | |
</dd> | |
<dt class="col-12"> | |
Profile Name | |
</dt> | |
<dd class="col-12"> | |
<?php echo $profile->firstName->localized->en_US ?> <?php echo $profile->lastName->localized->en_US ?> | |
</dd> | |
</dl> | |
</div> | |
</div> | |
<hr> | |
<h5>Share Post</h5> | |
<form action="posttextpost.php" required="required" method="post"> | |
<input type="hidden" name="profile" value="<?php echo $profile->id ?>"> | |
<textarea name="content" id="content" cols="30" rows="5" placeholder="What's on your mind?" class="form-control"></textarea> | |
<br> | |
<label for="">Privacy</label> | |
<select class="form-control" name="privacy" id="privacy"> | |
<option value="PUBLIC">Public</option> | |
<option value="CONNECTIONS">Connections Only</option> | |
</select> | |
<br> | |
<input type="submit" class="btn btn-danger btn-block" value="Proceed"> | |
</form> | |
</div> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
Output-

When you submit button this form the redirect to βposttextpost.phpβ so this page date mention below-
<?php | |
require_once "config.php"; | |
$profile = $_POST['profile']; | |
$content = $_POST['content']; | |
$privacy = $_POST['privacy']; | |
$post = $linkedin->linkedInTextPost($_SESSION['linkedInAccessToken'] , $profile, $content, $privacy); | |
$post = json_decode($post); | |
if (isset($post->id)) { | |
echo "POSTED"; | |
} else { | |
echo "FAILED."; | |
} | |
?> | |
<br> | |
<a href="/profile.php">BACK TO PROFILE</a> |
Output-






Iβm a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND