lime icon

Phosphorus and Lime

A Developer's Broadsheet

This blog has been deprecated. Please visit my new blog at klenwell.com/press.
PHP Greqo: Blogger Post Demo
I've updated the Greqo code to handle classic and beta accounts transparently -- well, almost. If you set up your script with the basic undifferentiated settings, like this, it will still work for either type of account. However, since it will try to authenticate using the Google Account ClientLogin interface as a first step, classic accounts will throw an error here. Nevertheless, as in the test script linked above, the request should still succeed.

To clarify how it works, consider the following code samples.

User Settings and Greqo Setup
// *** Google User Settings (keep safe!)
$_GOOGLE['user'] = 'jqblogger';
$_GOOGLE['pw'] = 'supersafe123';

// *** Blogger User Settings (for Blogger beta accounts, these will be the same)
$_BLOGGER['user'] = $_GOOGLE['user'];
$_BLOGGER['pw'] = $_GOOGLE['pw'];
$_BLOGGER['blog_id'] = '123456'; // if not sure, right click on link in your Blogger dashboard';

// *** Load Files
error_reporting(E_ALL);
session_start();
$_path_to_greqodir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR;
require_once($_path_to_greqodir . 'greqo_driver.inc.php');

// Important! (this function will globalize user settings and is required)
greqo_blogger_set_user_data($_BLOGGER['user'], $_BLOGGER['pw'], $_BLOGGER['blog_id']);


Generic Blogger Post
note: this will work for either type of account but will throw an error for classic account when it tries to authenticate under the new Google Accounts API
// prepare request (this will throw an error with classic Blogger accounts but post should still succeed)
if ( !greqo_request_clientlogin_token($_GOOGLE['user'], $_GOOGLE['pw'], 'blogger', 0) ) trigger_error('unable to get token');
if ( !greqo_blogger_request_api_url(0) ) $_SESSION['GDATA']['BLOGGER']['api_url'] = 'http://www.blogger.com';

// post
if ( $POST_DATA = greqo_blogger_post_entry($test_post_body, $test_post_title)
{
echo '<p style="color:green;">post succeeded</p>';
$_response = print_r($POST_DATA,1);
echo "<pre>{$_response}</pre>";
echo "<p><a href=\"{$POST_DATA['self_link']}\">click to see post</a></p>";
}
else
{
echo '<p style="color:red;">post failed</p>';
}


Now, if you know you are dealing with a classic (non-beta) account and wished to avoid the error warnings, remove the Google authentication part and just manually set the Blogger api url:

Classic Blogger Post
// prepare request (removed for Classic Blogger -- uncomment for new beta)
#if ( !greqo_request_clientlogin_token($_GOOGLE['user'], $_GOOGLE['pw'], 'blogger', 0) ) trigger_error('unable to get token');
#if ( !greqo_blogger_request_api_url(0) ) $_SESSION['GDATA']['BLOGGER']['api_url'] = 'http://www.blogger.com';

// manually set Blogger api url
$_SESSION['GDATA']['BLOGGER']['api_url'] = 'http://www.blogger.com';

// post
if ( $POST_DATA = greqo_blogger_post_entry($test_post_body, $test_post_title)
{
echo '<p style="color:green;">post succeeded</p>';
$_response = print_r($POST_DATA,1);
echo "<pre>{$_response}</pre>";
echo "<p><a href=\"{$POST_DATA['self_link']}\">click to see post</a></p>";
}
else
{
echo '<p style="color:red;">post failed</p>';
}


Greqo Google Code Home