Ahmed Sheta
Ahmed Sheta

Reputation: 50

Set Description, Draft and Permalink using Blogger API with PHP

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.

Upvotes: 3

Views: 1127

Answers (2)

Achin
Achin

Reputation: 9

You can try a workaround to set the permalink.

First, set the title of the new post to the custom slug you want. Then Publish your post, once the post is published you get the post url matching to your title. Then you can update the title to the desired title by fetching the post id and setting the title using code.

Upvotes: 0

Bouh
Bouh

Reputation: 1392

permalink

Unfortunately there is no way to set custom permalink to the posts using Blogger api, even the official "Try this API" tool don't have this feature, your code is fine it's just Blogger don't support it.

custom description

I don't think there is a way to add custom description as well, setDescription is not a valid method, you can 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); 

Upvotes: 3

Related Questions