Blogger v3 api post image with cotenet with php

Viewed 175

I'am using Blogger v3 api for post to my blog this is simple code

  $mypost = new Google_Post();
  $mypost->setTitle("title"));
  $mypost->setLabels(array('Label1', 'Label2'));
  $mypost->setContent("some html");
  $data = $blogger->posts->insert('0000000000000000000000', $mypost);  

actually i want to post to blog with an image i make little bit of search and seems possible to post an image to blogger but i found some other solution like using Google Picasa API

and here is some of my code for upload image to google

  try {



  $newMediaItems = [];



  //$photosLibraryClient = ......

  $uploadToken = $photosLibraryClient->upload(
  file_get_contents("a.jpg")  ,"name for image"
  );


  $newMediaItems[] =  
  PhotosLibraryResourceFactory::newMediaItem($uploadToken);

  try {
  $batchCreateResponse =
  $photosLibraryClient->batchCreateMediaItems($newMediaItems, ['albumId' 
  => $_SESSION['albumId']]);
  } catch (\Google\ApiCore\ApiException $e) {
  echo $templates->render('error', ['exception' => $e]);
  die();
  }
  } catch (\Google\ApiCore\ApiException $exception) {
  // Error during album creation
  } catch (\Google\ApiCore\ValidationException $e) {
  // Error during client creation
  echo $exception;
  } 

its upload an image to google photos and create new album but i can't retrieve image url (i need permanent url) any idea how can i get the image url i upload to google photos,

and did this the right way for post an image to blogger?

0 Answers
Related