【发布时间】:2015-05-04 03:56:50
【问题描述】:
我的一个朋友给了我这个使用 php 发布博客的代码。但它不起作用。我的服务器已经有 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;
?>
当我运行这段代码时。得到这样的结果
数组 ( [0] => 内容类型:application/atom+xml [1] => 内容长度:208 [2] => 授权:GoogleLogin auth= [3] =>
This is testing contnetto post in blog post.
) 布尔(假) 大批 ( [网址] => https://www.blogger.com/feeds/7493633362314585130/posts/default [内容类型] => [http_code] => 0 [header_size] => 0 [请求大小] => 417 [文件时间] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [总时间] => 4.001117 [namelookup_time] => 0.001279 [连接时间] => 0.007472 [pretransfer_time] => 0.026912 [大小上传] => 0 [大小下载] => 0 [速度下载] => 0 [速度上传] => 0 [下载内容长度] => -1 [上传内容长度] => -1 [starttransfer_time] => 1.028038 [重定向时间] => 0 [certinfo] => 数组 ( )
[redirect_url] =>
)
博主不会摆出任何姿势。你能帮我修复这个代码吗
对不起我的英语
【问题讨论】: