Skip to content

Instantly share code, notes, and snippets.

@balitax
Forked from arbo77/blogspot-list.php
Created June 30, 2016 04:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balitax/c14859afee36ed554fce80173ed894ae to your computer and use it in GitHub Desktop.
Save balitax/c14859afee36ed554fce80173ed894ae 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;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment