Be a Supporter!

Php: Curl: Gmail Rss Reading

  • 6,702 Views
  • 5 Replies
New Topic Respond to this Topic
elbekko
elbekko
  • Member since: Jul. 23, 2004
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Php: Curl: Gmail Rss Reading Jun. 9th, 2006 @ 12:36 PM Reply

PHP Main
----
Well, I'm not too good at writing tutorials, but I know people are interested, so here goes:
(yes I know it's a bunch of commented code =/)
37 lines of code, will show you something like this:
New messages in Gmail inbox: 0
----
<?php
// Username/pass
$username = 'elbekko';
$password = "80236045";

// Initialise cURL
$c = curl_init('https://'.$username.':'.$passwo
rd.'@gmail.google.com/gmail/feed/atom');

// We are defining headers here! The cookie doesn't matter, I just took one of my old ones =) If you leave the headers out, it will NOT WORK
// I took these from firefox with LiveHTTPHeaders when opening the feed, and removed unneeded ones
$headers = array(
"Host: mail.google.com",
"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4",
"Accept: text/xml,application/xml,application/xhtml
+xml,text/html;q=0.9,text/plain;q=0.8,imag
e/png,*/*;q=0.5",
"Accept-Language: en-gb,en;q=0.5",
"Accept-Encoding: text", # No gzip, it only clutters your code!
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
"Cookie: GX=DQAAAGwAAABOuf-Go9DoiR7F6-gFELuk7NpDDtV
SCSLxSB1sjgOJgq_4CB2BRFzLFk84DnOSzAEXZy-vJ
K-AGjvhtu6IUaUnJ2WOpYyv2MaDleaDR0R7It9Am5m
FG6i5kHMBOVugeUtyrR2N0ideLWw55PFpEIOg; GMAIL_AT=8879d3f33773aeb1-10bb52e204b; GMAIL_LOGIN=1149795949203/1149795949203/11
49795965875/1149795967531/1149795968015/11
49795970062/1149795970906/false/false; TZ=-120; GMAIL_RTT=47; GMAIL_LOGIN=T1149795949203/1149795949203/1
149795965875; SID=DQAAAGsAAABZIFzNinP2L98jk-2AfOySfLyN71
ST4NUjclt-vBovwmQxL23F4cX8xhBsso_hIVOdDBMa
XhKMxQJtCvPTMUZaG7i_HTiXjdJH80-kurWP4yTn0U
eOXk856Kz4rbFISLoPqigw8NNgDmwvklbClUet; S=gmail=t2x3QxCmf34:gmail_yj=7YxC8N0srqY:g
mproxy=S-dkzk2Cgas:gmproxy_yj=7IXK8bAXG1U; PREF=ID=10f88613f4bbde6f:TM=1149795971:LM=
1149795971:GM=1:S=WuznVPgf8tKv7cTA\n",
"Date: ".date(DATE_RFC822)
);
// We set some options
curl_setopt($c, CURLOPT_HTTPAUTH, CURLAUTH_ANY); // use authentication
curl_setopt($c, CURLOPT_HTTPHEADER, $headers); // send the headers
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); // We need to fetch something from a string, so no direct output!
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1); // we get redirected, so follow
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($c, CURLOPT_UNRESTRICTED_AUTH, 1); // always stay authorised
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 1);

// Show the result
$str = curl_exec($c); // Get it
preg_match('#<fullcount>(.*)</fullcount>#'
, $str, $array); // Use a regex to get what's between <fullcount>(.*)</fullcount>
echo 'New messages in [a href="http://gmail.com">Gmail inbox[/a>: '. $array[0]; // Output it

curl_close($c); // Close the curl stream
?>
----
Replace [ with <

I hope this is useful!

Greetings,

Elbekko


"My software never has bugs. It just develops random features. " - Unknown

[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]

BBS Signature
elbekko
elbekko
  • Member since: Jul. 23, 2004
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to Php: Curl: Gmail Rss Reading Jun. 9th, 2006 @ 12:39 PM Reply

If you're wodering; I changed my pass after I posted this :p
Silly me =/


"My software never has bugs. It just develops random features. " - Unknown

[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]

BBS Signature
elbekko
elbekko
  • Member since: Jul. 23, 2004
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to Php: Curl: Gmail Rss Reading Jun. 9th, 2006 @ 01:02 PM Reply

No you didn't... Change it now.


"My software never has bugs. It just develops random features. " - Unknown

[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]

BBS Signature
Rellizate
Rellizate
  • Member since: Feb. 27, 2006
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Php: Curl: Gmail Rss Reading Jun. 9th, 2006 @ 01:03 PM Reply

That was me, btw.

elbekko
elbekko
  • Member since: Jul. 23, 2004
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to Php: Curl: Gmail Rss Reading Jun. 9th, 2006 @ 01:20 PM Reply

Like I care about my NG account... =/


"My software never has bugs. It just develops random features. " - Unknown

[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]

BBS Signature
Rellizate
Rellizate
  • Member since: Feb. 27, 2006
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Php: Curl: Gmail Rss Reading Jun. 9th, 2006 @ 01:30 PM Reply

LOL ok.

*Tells people pass*

Just kidding.

=P