private function post($title, $content, $labels, $link) { try { $mypost = new \Google_Service_Blogger_Post(); $mypost->setTitle($title); $mypost->setContent($content); $mypost->setLabels($labels); for ($i = 0; $i < 2; $i++) { try { $article = $this->service->posts->insert($this->blogid, $mypost); break; } catch (\Exception $e) { if ($e->getCode() == 500) { sleep(1); continue; } throw $e; } } $postdata = array(); if (is_object($article)) { $postdata['id'] = $article->getId(); $postdata['title'] = $article->getTitle(); $postdata['selfLink'] = $link; $postdata['url'] = $article->getUrl(); $postdata['labels'] = $article->getLabels(); $postdata['published'] = $article->getPublished(); } return $postdata; } catch (\Exception $e) { $m = 'Cannot post to blogger because ' . $e->getCode() . ' ' . $e->getMessage(); $this->logger->logError($m); } }
} $data = $blogger->blogs->getByUrl('http://andyb2000.thebmwz3.co.uk/'); $load_file = file_get_contents("full.rss"); $read_file = explode("\n", $load_file); foreach ($read_file as $file_line) { if (strpos($file_line, "<title type=\"html\">") !== false) { list($junk, $content_title) = explode("<title type=\"html\">", $file_line); list($content_title, $junk) = explode("</title>", $content_title); } if (strpos($file_line, "<published>") !== false) { list($junk, $content_date) = explode("<published>", $file_line); list($content_date, $junk) = explode("</published>", $content_date); } if (strpos($file_line, "<content type=\"html\">") !== false) { list($junk, $content_desc) = explode("<content type=\"html\">", $file_line); @(list($content_desc, $junk) = @explode("</content>", $content_desc)); // echo "Found: $content_title on $content_date\n"; //creates a post object $mypost = new Google_Service_Blogger_Post(); $mypost->setTitle($content_title); $mypost->setContent(html_entity_decode($content_desc)); $out_published = date("c", strtotime($content_date)); $mypost->setPublished($out_published); $data = $blogger->posts->insert('1234567890', $mypost, array('isDraft' => true)); //post id needs here - put your blogger blog id echo "<BR><BR><PRE>"; var_dump($data); echo "</PRE><BR><BR>"; sleep(3); } }