Forum Moderators: coopster

Message Too Old, No Replies

Create a blogger post via PHP

         

onetry

1:10 pm on Jul 15, 2010 (gmt 0)

10+ Year Member



Hi,
I googled a little but can't find easy and working examples to create a post on my own blogger blog using PHP scripting.

It seems to me that curl has to be used ... but I can't make it work.

This is what I found:


<?php session_start();
$email = "user@gmail.com";
$pass = "password";
$blogID= urlencode("59846190469005183");

if(!isset($_SESSION['sessionToken'])) {

$ch = curl_init("https://www.google.com/accounts/ClientLogin?Email=$email&Passwd=$pass&service=blogger&accountType=GOOGLE");
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1);
$result = curl_exec($ch);
$resultArray = curl_getinfo($ch);
curl_close($ch);
$arr = explode("=",$result);
$token = $arr[3];
$_SESSION['sessionToken'] = $token;
}

$entry = "<entry xmlns=’http://www.w3.org/2005/Atom’>

<title type=’text’>Title of blog post </title>

<content type=’xhtml’>

This is testing content to post in blog post.

</content>

</entry>";

$len = strlen($entry);

$headers = array("Content-type: application/atom+xml","Content-Length: {$len}","Authorization: GoogleLogin auth={$_SESSION['sessionToken']}","$entry");

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.blogger.com/feeds/$blogID/posts/default");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
curl_setopt($ch, CURLOPT_POST, true);
$result = curl_exec($ch);
$ERROR_CODE = curl_getinfo($ch);
curl_close($ch);

echo '<pre>';
print_r($headers);
var_dump($result);
print_r($ERROR_CODE);
exit;

?>


Perhaps someone can help ?

Thanks.

andrewsmd

3:05 pm on Jul 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You didn't explain your problem very well at all. What exactly are you trying to do. Go through it step by step.