-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreader.php
55 lines (49 loc) · 2.15 KB
/
reader.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
<?php
$user="[email protected]";
$pass="GOOGLE PASSWORD";
$readerId="readerID here";
$feed_url = "http://www.google.com/reader/api/0/unread-count"; //URL for Google Reader unread counts
//Login to Google
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$googleResponse = curl_exec($ch);
curl_close ($ch);
//Retrieve the SID and Auth parameters for further Google transactions
$sid = substr($googleResponse,4,203); //I don't believe we need this, but left in
$pos = strpos($googleResponse,"Auth=");
$pos = $pos+5;
$auth = substr($googleResponse,$pos); //This auth token must be passed with request. A new one is generated each time.
// it may raise eyebrows or trigger a shutdown on Google servers. Consider
// saving this token for 24 hours?
//Connect to Google Reader and retrieve the unread counts
$headers = array(
"Authorization: GoogleLogin auth=" . $auth,
"GData-Version: 3.0",
);
$agent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.7) Gecko/20100713 Firefox/3.6.7";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $feed_url);
curl_setopt($curl, CURLOPT_USERAGENT, $agent);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl); //put the entire XML response into $output
curl_close ($curl);
//------- Parse the XML ----------
//to do: put user specific strings into DB
$xml = new SimpleXMLElement($output); //create a SimpleXML object out of this XML text
$myID = "user/" . $readerId . "/state/com.google/reading-list";
$path = "//object[string[@name='id'] = '$myID']/number[@name='count']"; //path to count
$unreads = $xml->xpath($path);
// to do: use mapping formula for changing ranges on meter. Save ranges in DB.
if ($unreads[0] <= 510)
$val = $unreads[0] / 2;
else
$val = 255;
echo chr($val);
?>