-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
124 lines (108 loc) · 3.22 KB
/
index.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
// exec time
// set_time_limit(60 * 10);
// add your feedly API credentials
$user_id = '';
$access_token = '';
function call_api($user_id, $access_token, $continuation) {
//
$url = 'https://cloud.feedly.com/v3/streams/contents?streamId=user/' . $user_id . '/tag/global.saved&count=500';
// optional continuation input
if ($continuation) {
$url = $url . '&continuation=' . $continuation;
}
// curl
$curl = curl_init();
// options
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: OAuth ' . $access_token,
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// requesting saved items
$result = curl_exec($curl);
curl_close($curl);
$result = json_decode($result);
return $result;
}
// main
$bookmarks = [];
$continuation = null;
while (true) {
$chunked = call_api($user_id, $access_token, $continuation);
// nothing return; exit
if (!$chunked) {
var_dump($chunked);
echo count($bookmarks);
break;
}
// api error
if ($chunked->errorCode ?? false) {
var_dump($chunked);
echo count($bookmarks);
exit;
}
// success request
// $items = array_merge($items, $chunked->items);
foreach ($chunked->items as $item) {
// new bookmark entry
$bookmark = [
'title' => $item->title,
'href' => '',
'add_date' => $item->actionTimestamp,
'last_modified' => $item->actionTimestamp,
];
// href cases
if ($item->canonicalUrl ?? false) {
$bookmark['href'] = $item->canonicalUrl;
}
elseif ($item->canonical[0] ?? false) {
$bookmark['href'] = $item->canonical[0]->href;
}
elseif ($item->originId ?? false) {
$bookmark['href'] = $item->originId;
}
elseif ($item->alternate[0] ?? false) {
$bookmark['href'] = $item->alternate[0]->href;
}
else {
// new exception
var_dump($item);
exit;
}
// add bookmark
array_push($bookmarks, $bookmark);
}
// check for pagination
if ($chunked->continuation ?? false) {
// prepare for next request
$continuation = $chunked->continuation;
}
else {
// var_dump($chunked);
// exit;
// end of the stream
break;
}
// sleep, just in case api rate limit
sleep(5);
}
// exit;
?>
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!-- This is an automatically generated file.
It will be read and overwritten.
DO NOT EDIT! -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<!-- <H1>Bookmarks Menu</H1> -->
<DL><p>
<DT><H3>Feedly (Total: <?php echo count($bookmarks) ?>)</H3>
<DL><p>
<?php foreach ($bookmarks as $bookmark): ?>
<DT><A HREF="<?php echo $bookmark['href'] ?>" ADD_DATE="<?php echo $bookmark['add_date'] ?>" LAST_MODIFIED="<?php echo $bookmark['last_modified'] ?>"><?php echo $bookmark['title'] ?></A>
<?php endforeach; ?>
</DL><p>
</DL>
<!-- end of html file -->