Set Description, Draft and Permalink using Blogger API with PHP

Viewed 596

I really need your help with this matter. I'm looking for a solution for about 3 months now, but really the Blogger API is not easy to deal with because Blogger don't even provide examples.

I can create and publish new posts with PHP script and I have done all things, but I can't set the Post's description, permalink, or even making the new post as draft.

The following is a piece of my code that creating the post.

<?php

    $mypost = new Google_Post();
    $mypost->setTitle('My Post Title');
    $mypost->setContent('This is My Content');
    $mypost->setLabels( array( 'News','Weather', 'Media' ) );
    $mypost->setCustomMetaData('My_CUSTOM_META_DATA' . time()); // Nothing changed
    $mypost->setcustomMetaData('This is the description for you');  //Nothing Changed
    $mypost->setDescription('New Description');   // Nothing Changed
    $mypost->setUrl('testseturl');   // Nothing Changed
    $mypost->setPublished('2021-08-27T23:07:00-07:00');  // Worked as Schedule post

    $data = $blogger->posts->insert('My BlogID', $mypost); 

    echo "<pre>";
    var_dump($data);
    echo "</pre>";
?>

As you can see I can't set the permalink and I tried several thing such as adding the full URL, and also adding only the custom permalink text + html, but I failed.

I tried also the description several times, but every time I found the description's post empty.

Also I can' set the post as Draft and I have to do this manually from the blog itself.

Blogger doesn't provide any help docs for PHP, and the new Beta client library on github is for all Google products and I wasn't able to use it. I use the library Google API PHP Client 0.6.7 found here although it's deprecated.

The only topic I found in this blog, and it's the same code that I use, but he didn't mentioned anything about permalink, draft, or description.

Please help me as you can.

Thanks.

1 Answers

permalink

unfortunately there is no way to set custom permalink to the posts using Blogger api, even the the official "Try this API" tool wont set it, there are no problems in your code, it's just Blogger don't support it.

custom description

I don't think there is a way to add a custom description, setDescription is not a valid method, check all the supported methods here

draft post

to create a post draft you can do it like this

$optParams = array('isDraft' => true);
$data = $blogger->posts->insert('My BlogID', $mypost, $optParams); 
Related