Auto post into Blogspot using php code?

Hi, the following code will help to auto post into blogspot using php code. We can post into blogspot blog from your application by this code. It will be useful when we post one link or some content to post into social sites from your application then we can use this code.

 <?php session_start();
    $email = "[email protected]";
    $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;

    ?>

Hope that it will be useful.

Thank you,

Anil Kumar Panigrahi

With more than 10 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ... Contact : [email protected]

You may also like...

39 Responses

  1. nickace says:

    Hey Thank you very much, and the timing is good, I am just looking for this.
    but I have tried it everthing works but My post did not appear, what do you think is wrong

    Thnks

  2. harry says:

    Thanks its helpfull… but How to set the label?

  3. azzaam says:

    where i set the code?

  4. Hello azzam,

    Title of blog post

    This is testing contnetto post in blog post.

    In this code we have to change the what you want to post into your blogspot.
    and run this file at at http://localhost/blogpost.php , if you save the file blogpost.php, hope you understand.

  5. mizake says:

    Hi thank you..for this great info
    one question..can I attach this code into classic template since a blogger classic template is work with php code..?

  6. Hi mizake,

    This script will work for post content into blogger, using php code. , for that you should have curl support php version., if it is available then with this code you can post the content into blogspot blogger.

  7. hacobi1102 says:

    This is work very good!
    Thank you
    Can you give me your Yahoo ID?
    Please PM me with my Yahoo ID: ng0ngan.viyeu
    I have some ask with this code
    I want to u this get RSS content and post to blogspot !
    Thank you very much!

  8. hacobi1102 says:

    that is my blog use this code: http://masterbaunet.blogspot.com/

    And link to code: http://hacobi.com/test/blogger.php
    Im added function time() in title of post 🙂

    This is work very good!
    Thank you
    Can you give me your Yahoo ID?
    Please PM me with my Yahoo ID: ng0ngan.viyeu
    I have some ask with this code
    I want to u this get RSS content and post to blogspot !
    Thank you very much!

  9. Esaul Daris says:

    hacobi1102,

    both of your blog was not found. One of them was banned by google. Is that meaned google not agreed with every automatic post with any trick?

    I need your reply, or Anil reply.

    regards,
    Esaul Daris.

  10. Marcus says:

    Hi Anil,

    I don’t have my personal server. So do you have any idea how to execute your code. Perhaps any free php hosting site or can I execute your code on my windows based computer when I am online? Thanks

    Regards,
    Marcus

  11. @Marcus

    You can run from your localhost with your credentials but in your apache support CURL package.

  12. tv izle says:

    Thank you very much and the timing is good, I am just…

  13. upul suresh says:

    Thank a lot

    Your above coding I used and work properly in http://buyandsell-srilanka.blogspot.com

    Thank you very much

  14. Krishna says:

    Hello, Nice article and very useful .

    Thanks

  15. KIran says:

    Hello,
    Nice article . I think there is a limit in blogger on number of automated posts / day .
    Here is a simple tool for sending rss/atom feeds content to multiple blogger.com accounts in single click .

    Thanks

  16. Surinder says:

    I have curl enabled server but this code doesn’t work for me 🙁
    my blog is : http://thebloggingtricks.blogspot.com/
    it returned this :

    bool(false)
    Array
    (
    [url] => https://www.blogger.com/feeds/3139338840219246749/posts/default
    [content_type] =>
    [http_code] => 0
    [header_size] => 0
    [request_size] => 428
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 4.000643
    [namelookup_time] => 0.002279
    [connect_time] => 0.00992
    [pretransfer_time] => 0.037535
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => -1
    [upload_content_length] => -1
    [starttransfer_time] => 2.037611
    [redirect_time] => 0
    [certinfo] => Array
    (
    )

    [redirect_url] =>
    )

  17. gopi says:

    NIce Article.

  18. divyesh says:

    i use your code but i have one problem when my page load it display all element but $token = $arr[3]; was every time empty so how to solve this pro..

    all element detail ===

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

    123 magic.

    )
    bool(false)
    Array
    (
    [url] => https://www.blogger.com/feeds/6629929181202825897/posts/default
    [content_type] =>
    [http_code] => 0
    [header_size] => 0
    [request_size] => 369
    [filetime] => -1
    [ssl_verify_result] => 20
    [redirect_count] => 0
    [total_time] => 4.29
    [namelookup_time] => 0
    [connect_time] => 0.094
    [pretransfer_time] => 0.281
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => -1
    [upload_content_length] => -1
    [starttransfer_time] => 1.295
    [redirect_time] => 0
    )

    so plz help me

  19. parth patel says:

    hello bro will u help me to develop admin panel for my web site..??

  20. vinayak says:

    is it possible to share without using password?

  21. chris says:

    Hello,

    How to get content from other website using curl and then autopost the result to blogspot ?

    thanks
    chris

  22. Sanjay Samanta says:

    hello ,
    I used your code but i have faced the problem. My code out put as

    Array
    (
    [0] => Content-type: application/atom+xml
    [1] => Content-Length: 204
    [2] => Authorization: Google Login auth=viewport content
    [3] =>

    This is testing contnet to post in blog post.

    )
    bool(false)

  23. Awesome post!!! Thanks for sharing information about PHP courses and PHP classes. This blog post looking interesting. Very useful information. Good going. http://goo.gl/IoIakF

  24. nandhini seo says:

    Your site is very informative and your articles are wonderful.

  25. سوق says:

    i hope that it’s still working
    thanks

  26. Nice to read your article! very informative.So, please keep posting Useful Stuff here Thanks….

  27. vadivel says:

    Nice Post, Php problems and Solutions

  28. Vadivels says:

    Hey Very nice article, you want any hd wallpapers.

  29. Vadivels says:

    Hey Very nice article, you want any hd wallpapers. http://imgcluster.com

  30. PHP Classes says:

    Hello, Thank you much I am looking for this from some days. It is very heipful. PHP Classes!

  31. Nice Post, Php problems and Solutions

  32. pranjali says:

    Thanks for sharing such a source of information. which is important in web development.

Leave a Reply

Your email address will not be published. Required fields are marked *