Skip to content

Instantly share code, notes, and snippets.

@arbo77
Created July 29, 2012 20:21
Show Gist options
  • Save arbo77/3201644 to your computer and use it in GitHub Desktop.
Save arbo77/3201644 to your computer and use it in GitHub Desktop.
Blogspot content parser using PHP CUrl, last update using Google Blogger API
<?php
/*
* read more on :
* https://developers.google.com/blogger/docs/3.0/getting_started
*
*/
$key["server"] = "YOUR_BLOGGER_API_KEY";
$blogId = "YOUR_BLOG_API";
$url = "https://www.googleapis.com/blogger/v3/blogs/$blogId/posts?key=$key[server]";
try{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$resp = curl_exec($ch);
curl_close($ch);
$posts = json_decode($resp, true);
// do whatever you want with this data responses
}catch(Exception $ex){
echo $ex->getMessage();
}
?>
<?php
/*
* read more on :
* https://developers.google.com/blogger/docs/3.0/getting_started
*
*/
$key["server"] = "YOUR_BLOGGER_API_KEY";
$blogId = "YOUR_BLOG_API";
$url = "https://www.googleapis.com/blogger/v3/blogs/$blogId/posts/$_GET[id]?key=$key[server]";
try{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$resp = curl_exec($ch);
curl_close($ch);
$posts = json_decode($resp, true);
// do whatever you want with this data responses
}catch(Exception $ex){
echo $ex->getMessage();
}
?>
<?php
function parseBlogSpot($url){ // $url is full blogspot URL
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Opera/9.50 (J2ME/MIDP; Opera Mini/4.0.9800/209; U; en)");
$resp = curl_exec($ch);
curl_close($ch);
$lines = explode("\n",$resp);
$start = "<div class='post hentry'>"; // start marker
$end = "<div class='post-footer'>"; // stop marker
$tmp = "";
$doParse = false;
foreach($lines as $line){
if(trim($line) == $start){
$doParse = true;
}
if(trim($line) == $end){
break;
}
if($doParse){
$tmp .= $line."\n";
}
}
return $tmp;
}
?>
@indiarocks08
Copy link

how to create a new post in blogger using api v3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment