Created
July 29, 2012 20:21
-
-
Save arbo77/3201644 to your computer and use it in GitHub Desktop.
Blogspot content parser using PHP CUrl, last update using Google Blogger API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
?> |
Hi, thank you for your recommendation. I know DOM or SimpleXML are powerful, but did you ever try parse blogspot content using DOM or SimpleXML without error? I've done that, and always got an error when parsing, the problem is DOM or SimpleXML cannot parse content with embedded script.
Well, actually there is a simple solution to libxml components.
libxml_use_internal_errors(true);
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
I recommend you learn about PHP's DOM parsing and things like SimpleXML. Much more powerful and robust than looking for starting and ending strings.