php + curl发布在博客脚本中不起作用

时间:2014-05-05 05:12:22

标签: php curl

我刚接触 stackoverflow ,希望能与你合作。

这是我的问题,

我有一个PHP代码,我尝试通过此脚本发布到我的博客帐户。我已经安装了CURL。但发布不起作用。我的代码中的错误是什么。

<?php 
    session_start();
    $email = "xxxxx@gmail.com";
    $pass = "xxxxxxxxxx";
    $blogID= urlencode("xxxxxxxxxxxxxxxx");  

    // 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'>hi</title>

    <content type='xhtml'>

     welcome..

    </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;

    ?>

我的输出是。

Array
(
    [0] => Content-type: application/atom+xml
    [1] => Content-Length: 162
    [2] => Authorization: GoogleLogin auth=1
    [3] => 





     welcome..




)
boolean false
Array
(
    [url] => https://www.blogger.com/feeds/6304924319904337556/posts/default
    [content_type] => 
    [http_code] => 0
    [header_size] => 0
    [request_size] => 0
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 4.204
    [namelookup_time] => 0.204
    [connect_time] => 0
    [pretransfer_time] => 0
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => -1
    [upload_content_length] => -1
    [starttransfer_time] => 0
    [redirect_time] => 0
    [certinfo] => Array
        (
        )

    [primary_ip] => 74.125.200.191
    [primary_port] => 443
    [local_ip] => 
    [local_port] => 0
    [redirect_url] => 
)
谢谢。

0 个答案:

没有答案