-
Notifications
You must be signed in to change notification settings - Fork 0
/
pocket.php
72 lines (58 loc) · 1.97 KB
/
pocket.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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/vendor/autoload.php'; // change path as needed
if(isset($_SERVER['HTTPS'])){
$protocol = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http";
}
else{
$protocol = 'http';
}
$baseurl = $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$pocket_app = '';
$pocket_key = '';
$pocket_token = '';
$linkedIn = new Happyr\LinkedIn\LinkedIn($lnkdn_id, $lnkdn_secret);
if($_GET['auth-status'] == 'success' && $_GET['auth-from'] == 'pocket'){
echo 'Linkedin successfully!';
}elseif ($segments[1] == 'pocket') {
$request_token = $_GET['request_token'];
$url = 'https://getpocket.com/v3/oauth/authorize';
$data = array(
'consumer_key' => $pocket_key,
'code' => $request_token
);
$q = http_build_query($data);
$options = array(
'http' => array(
'method' => 'POST',
'content' => $q,
'header' => "Content-Type: application/x-www-form-urlencoded\r\n".
"Content-Length: ".strlen($q)."\r\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$access_token = explode('&',$result);
$accessToken = str_replace('access_token=', '', $access_token[0]);
header('Location: '.$baseurl.'networks?auth-status=success&auth-from=pocket');
}
$url = 'https://getpocket.com/v3/oauth/request';
$redirect_uri = $baseurl.'pocket';
$data = array(
'consumer_key' => $pocket_key,
'redirect_uri' => $redirect_uri
);
$options = array(
'http' => array(
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$code = explode('=',$result);
$request_token = $code[1];
$pocket_login = 'https://getpocket.com/auth/authorize?request_token=%s&redirect_uri=%s?request_token=%s',$request_token,$redirect_uri,$request_token;
header('Location: '.$pocket_login);