Answer the question
In order to leave comments, you need to log in
How to set the “main” photo in a blogger when creating (api) an article?
Good afternoon!
Recently I began to study the Google API/API Blogger, I have already learned how to create posts in it, but I just can’t figure out how to take a photo that will then end up on a thumbnail for an article. When I manually upload a photo to an article through the blogger editor, it is automatically marked, and when the article is saved, it becomes a thumbnail. I even tried to take the HTML code from the editor and use it when working with the API, but this only affected the content, but the photo, as the main one, is not marked.
Here is part of the code:
$service = new Google_Service_Blogger( $client );
$html = array();
$html[] = '
<div class="separator" style="clear: both; text-align: center;">
<a href="https://'.$img.'" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" src="https://'.$img.'" />
</a>
</div>';
$html[] = '<p>Content</p>';
$html = implode( '', $html );
$image = new Google_Service_Blogger_PostImages();
$image->setUrl( 'https://'.$img );
$data = new Google_Service_Blogger_Post();
$data->setTitle( 'Test' );
$data->setContent( $html );
$data->setLabels( $labels );
$data->setImages( array( $image ) );
$res = $service->posts->insert( $blogID, $data, array(
'isDraft' => true,
'fetchImages' => true,
) );
echo '<pre>'.print_r( $res, true ).'</pre>';
$data->setImages( array( $image ) );
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question