πŸš€ DevOps & SRE Certification Program πŸ“… Starting: 1st of Every Month 🀝 +91 8409492687 πŸ” Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

How to post form data from PHP 7 using LinkedIn API?

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>

Table of Contents

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-

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.