one of my friends gave me this code for blogger posting using php. but it's not working. my server already have cURL
<?php session_start();
$email = "blogger_email@gmail.com";
$pass = "password";
$blogID= urlencode("blogger_id"); // like 6304924319904337556
// Do Not Modify Below Code
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 contnetto 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;
?>
when i run this code. getting result like this
Array ( [0] => Content-type: application/atom+xml [1] => Content-Length: 208 [2] => Authorization: GoogleLogin auth= [3] =>
This is testing contnetto post in blog post.
) bool(false) Array ( [url] => https://www.blogger.com/feeds/7493633362314585130/posts/default [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 417 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 4.001117 [namelookup_time] => 0.001279 [connect_time] => 0.007472 [pretransfer_time] => 0.026912 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 1.028038 [redirect_time] => 0 [certinfo] => Array ( )
[redirect_url] =>
)
blogger won't posing anything . can you help me to fix this code
and sorry for my English
Try to use PHPMailer As explained here this also can be used for blogger posting using php sent to your email address on your blog that contains your secret key. Here is the code:
include('class.phpmailer.php');
$gmail_your_name = "YOUR NAME";
$gmail_username = "YOUR GMAIL USERNAME";
$gmail_password = "YOUR GMAIL PASSWORD";
$gmail_email = "YOUR GMAIL EMAIL ADDRESS";
$blogger_secret_key = "YOUR BLOGGER SECRET KEY";
$blogger_url = "YOUR BLOGGER URL";
$image_location = 'C:/YOUR LOCATION OF IMAGE/IMAGE.JPG';
$email_title = "EMAIL TITLE";
$email_body = "EMAIL BODY"; // HTML OK
$mail = new PHPMailer();
$mail->IsHTML(true);
$mail->IsSMTP();
$mail->;SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = $gmail_username;
$mail->Password = $gmail_password;
$fromname = $gmail_your_name;
$To = trim($gmail_username.'.'.$blogger_secret_key.'@blogger.com',"
");
$mail->AddAttachment($image_location);
$mail->From = $gmail_email;
$mail->FromName = $fromname;
$mail->Subject = $email_title;
$mail->Body = $email_body;
$mail->AddAddress($To);
$mail->set('X-Priority', '3'); //Priority 1 = High, 3 = Normal, 5 = low
$mail->Send();