-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedin.php
90 lines (87 loc) · 3.24 KB
/
linkedin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
error_reporting(~E_NOTICE);
$response_type = "code";
$client_id = "81j99zm1ygvajl";
$redirect_uri = "https://app.rahberashraf.com/linkedin.php";
$client_secret = "aFdjSw3mKv8rdMYN";
$scope = "r_liteprofile%20r_emailaddress%20w_member_social";
$code = "";
$current_uri = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$firstString ="https://www.linkedin.com/oauth/v2/authorization?response_type=".$response_type."&client_id=".$client_id."&redirect_uri=".$redirect_uri."&scope=".$scope;
if($_GET['code']){
$code = $_GET['code'];
}
if($_POST['frmAction']=="access"){
$ch = curl_init();
$request_headers = array(
"POST /oauth/v2/accessToken HTTP/1.1",
"Host: www.linkedin.com",
"Content-Type: application/x-www-form-urlencoded"
);
$secondString = "client_id=".$client_id."&grant_type=authorization_code&code=".$code."&redirect_uri=".$redirect_uri."&client_secret=".$client_secret;
curl_setopt($ch, CURLOPT_POSTFIELDS, $secondString );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "https://www.linkedin.com/oauth/v2/accessToken");
$result = (curl_exec($ch));
$resultt = json_decode($result);
if($resultt->access_token){
$oo = $resultt->access_token;
}else if($resultt->error){
$oo = $resultt->error;
}else{
$oo = "There was an error";
}
curl_close($ch);
}else if($_POST['frmAction']=="profile"){
$access_token = $_POST['access_token'];
$oo = $access_token;
$ch = curl_init();
$request_headers = array(
"GET /v2/me HTTP/1.1",
"Host: api.linkedin.com",
"X-RestLi-Protocol-Version:2.0.0",
"Authorization: Bearer #".$access_token,
"Connection: Keep-Alive"
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "https://api.linkedin.com/v2/me?projection=(localizedFirstName,profilePicture(displayImage~:playableStreams))&oauth2_access_token=".$access_token);
$result = (curl_exec($ch));
$resultt = json_decode($result);
if($resultt->localizedFirstName){
$profile = $resultt->localizedFirstName;
$image = resultt[0][1][1][0][1]->identifier;
echo resultt[0] . "<br />";
echo resultt[0][1] . "<br />";
echo resultt[0][1][1] . "<br />";
echo resultt[0][1][1][0] . "<br />";
}else if($resultt->serviceErrorCode){
$profile = $resultt->message;
}else{
$profile = "There was an error";
}
curl_close($ch);
}
?>
<br />
<br />
<br />
<a href ="<?php echo $firstString ?>" ><img src="https://content.linkedin.com/content/dam/developer/global/en_US/site/img/signin-button.png" /></a>
<br />
<br />
<br />
<form action="<?php echo $current_uri?>" method="post">
<input type="hidden" name="frmAction" value="access">
The Authorization Code is <input type="text" value="<?php echo $code; ?>" />
<input type="submit" value="Fetch Access Code">
</form>
<br />
<br />
<form action="<?php echo $current_uri?>" method="post">
<input type="hidden" name="frmAction" value="profile">
The Access Code is <input type="text" name ="access_token" value="<?php echo $oo; ?>" />
<input type="submit" value="Fetch Profile">
</form>
<br />
The Profile is <input type="text" value="<?php echo $profile; ?>" />
<br />
<img src="<?php echo $image; ?>" alt="" />