Recent Articles

Get Google Reader feeds with PHP

 

Simple PHP access control

Access control can be a complicated process.  Taking a “simple, but not simpler” approach allows extensibility in this basic task of web application development.

Read on
 

EE’s {weblog_short_name} and CSS

Sometimes CSS can be used in very creative ways, especially when there’s dynamic content.

Read on
 

DOM Trick: de-thumb an image URL

When ExpressionEngine auto-creates a thumbnail image, it gives the option for creating the markup to display the full size image in a new, pop-up window or in a blank window.  If you’re like me, those options aren’t optimal.  So I put together a handy 4-line Javascript DOM trick to give me other choices.

Read on
 

Resource: Findable Websites

There’s many books and resources available on designing client- and server-side web sites, but few which focus on the practical methods of creating web sites that users can find.  This is one worth mentioning.

Read on
 

Get Google Reader feeds with PHP

Here is a PHP script for pulling in unread Google Reader feeds.  Reposted from Dave Shea’s blog.

// ----------------------------------------
// Google Reader Authentication in PHP
// a basic script to get you in the door of 
// Google's unofficial Reader API
// by Dave Shea, mezzoblue.com
// ----------------------------------------

// cobbled together from notes on:
// http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI

// these are the urls we'll need to access various services
$urlAuth "https://www.google.com/accounts/ClientLogin";
$urlAtom "http://www.google.com/reader/atom";

// our array of login data
$login = array(
  
"service" => "reader",
  
"continue" => "http://www.google.com/",

  
// Google id-only of the account holder
  // ie. for example@gmail.com, just use example
  
"Email" => "google-id"

  
// the account's password in plaintext
  
"Passwd" => "password",

  
// an identifying name for your script, can be anything
  
"source" => "my reader script",
);


// first step is to authenticae
// let's build a POST request using the login data array
$postRequest "";
foreach(
$login as $field => $value{
  $postRequest 
.= $field "=" $value "&";
}

// start buffering what we get back
ob_start();
$ch curl_init($urlAuth);
curl_setopt ($chCURLOPT_POSTtrue);
curl_setopt ($chCURLOPT_POSTFIELDS$postRequest);
curl_setopt ($chCURLOPT_FOLLOWLOCATIONtrue);
curl_exec ($ch);
curl_close ($ch);
// throw the buffer into a variable
$loginResult ob_get_contents(); 
ob_end_clean();

// we just received three lines of ugliness to contend with.
// each line is a huge string preceded with an ID
// the IDs are: SID, LSID, and Auth; we only want SID
// let's use some string parsing to weed it out
if ($i strstr($loginResult"LSID")) {
  $SID 
substr($loginResult0
    (
strlen($loginResult) - strlen($i)));
  
$SID rtrim(substr($SID4, (strlen($SID) - 4)));
}
// so we've found the SID
// now we can build the cookie that gets us in the door
$cookie "SID=" $SID 
  
"; domain=.google.com; path=/; expires=1600000000";


// this builds the action we'd like the API to perform
// in this case, it's getting our list of unread items
$action $urlAtom 
  
"/user/-/state/com.google/reading-list";
  
// note that the hyphen above is a shortcut
  // for "the currently logged-in user"


// start buffering what we get back
ob_start(); 
$ch curl_init();
curl_setopt ($chCURLOPT_URL$action);
curl_setopt ($chCURLOPT_HTTPGETtrue);
curl_setopt ($chCURLOPT_COOKIE$cookie);
curl_exec ($ch);
curl_close ($ch);
// throw the buffer into a variable
$xml ob_get_contents();
ob_end_clean();

// and finally, let's take a look.
echo $xml
01/05 at 08:06 AM

Comments

  No one's commented yet. Add yours!

Add Comment

Commenting is not available in this channel entry.
© 2002-2010 | carvingCode ™ | carving unique nooks in the web ™ | simple, but not simpler ™