Zend Google data API
I was going to implement AuthSub authentication for Ngeblog, when i found that Zend has done it all for me. Zend framework now has GData supported.
As usual, i grabbed it and tasted it a bit. And as you’ve might suspected, sweet!
Here you go, try it out yourself.
<?php
/**
* Testing Zend_Gdata for reading Blogger
* Written by Eris Ristemena (http://www.ngoprekweb.com)
*
*/
set_include_path(dirname(__FILE__) . '/Zend_Gdata');
require_once 'Zend.php';
Zend::loadClass('Zend_Gdata_AuthSub');
Zend::loadClass('Zend_Gdata');
Zend::loadClass('Zend_Feed');
session_start();
if (!isset($_SESSION['blogger_token'])) {
if (isset($_GET['token'])){
//convert the single-use token to a session token
try {
$session_token = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
$_SESSION['blogger_token'] = $session_token;
} catch ( Exception $e ) {
echo $e->getMessage();
exit;
}
} else {
//display link to generate single-use token
echo 'Click <a href="'. Zend_Gdata_AuthSub::getAuthSubTokenUri('http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'],"http://beta.blogger.com/feeds",0,1).'">here</a> to authorize this application.';
exit();
}
}
if (isset($_GET['logout'])) {
Zend_Gdata_AuthSub::AuthSubRevokeToken($_SESSION['blogger_token']);
unset($_SESSION['blogger_token']);
header('Location: '.$_SERVER['PHP_SELF']);
exit;
}
echo '<a href=
"'.$_SERVER['PHP_SELF'].'?logout">Logout</a>'; echo '<hr size="1" />';
try {
$client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['blogger_token']);
$gdata = new Zend_Gdata($client);
$feed = $gdata->getFeed("http://www.blogger.com/feeds/default/blogs");
foreach ($feed as $item) {
echo '<h3><a href="'.$item->link("alternate").'">' . $item->title() . '</a></h3>';
$_id = explode("/",(string) $item->id());
$blogid = $_id[count($_id)-1];
$feed1 = $gdata->getFeed("http://www.blogger.com/feeds/$blogid/posts/summary");
echo "<ul>";
foreach ($feed1 as $item1) {
echo "<li>";
echo "<a href=\"{$item1->link('alternate')}\">{$item1->title()}</a><br />";
echo "{$item1->summary()}<br />";
echo "</li>";
}
echo "</ul>";
}
} catch ( Exception $e ) {
echo $e->getMessage();
}
?>
Categories: PHP
Hi,
I’ve been trying to integrate my mobile application to post to blogger. I tried playing with your script which helped me understand a lot about how it works. In fact i learnt more from here than from the actual google explanation.
I’m not having luck though, because i’m not a very technical person. So finally i have to ask “would be interested in helping me out?”