Blogger post using PHP API
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
session_start();
require_once dirname(__FILE__) . '/GoogleClientApi/src/Google/autoload.php';
require_once dirname(__FILE__).'/GoogleClientApi/src/Google/Client.php';
require_once dirname(__FILE__).'/GoogleClientApi/src/Google/Service.php';
require_once dirname(__FILE__).'/GoogleClientApi/src/Google/Model.php';
require_once dirname(__FILE__).'/GoogleClientApi/src/Google/Collection.php';
require_once dirname(__FILE__).'/GoogleClientApi/src/Google/Config.php';
require_once dirname(__FILE__).'/GoogleClientApi/src/Google/Service/Resource.php';
require_once dirname(__FILE__).'/GoogleClientApi/src/Google/Service/Blogger.php';
//echo '<pre>';
$scriptUri = "<redirect url>";
$client = new Google_Client();
$client->setAccessType('online'); // default: offline
$client->setApplicationName('<appName>'); //name of the application
$client->setClientId('<clientID>'); //insert your client id
$client->setClientSecret('<clientsecret>'); //insert your client secret
$client->setRedirectUri($scriptUri); //redirects to same url
$client->setDeveloperKey('<developerkey>'); // API key (at bottom of page)
$client->setScopes(array('https://www.googleapis.com/auth/blogger')); //since we are going to use blogger services
if (isset($_GET['logout'])) { // logout: destroy token
unset($_SESSION['token']);
header("Location: ".$scriptUri);
}
if (isset($_GET['code'])) { // we received the positive auth callback, get the token and store it in session
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header("Location: bloglist.php");
}
if (isset($_SESSION['token'])) { // extract token from session and configure client
$token = $_SESSION['token'];
$client->setAccessToken($token);
}
if (!$client->getAccessToken()) { // auth call to google
$authUrl = $client->createAuthUrl();
header("Location: ".$authUrl);
//die;
}
if(isset($_POST['submit'])){
$blogger = new Google_Service_Blogger($client);
//you can get the data about the blog by getByUrl
$blog = $blogger->blogs->getByUrl(array('url'=>'<blogurl>'));
//creates a post object
$mypost = new Google_Service_Blogger_Post();
$mypost->setTitle($_POST['title']);
$mypost->setContent($_POST['desc']);
//echo $blog->getId();
$data = $blogger->posts->insert($blog->getId(), $mypost);
header("Location: bloglist.php");
}else if(isset($_GET['delete']) && isset($_GET['postid'])){
$blogger = new Google_Service_Blogger($client);
$blog = $blogger->blogs->getByUrl(array('url'=>'<blogurl>'));
$data = $blogger->posts->delete($blog->getId(), $_GET['postid']);
header("Location: bloglist.php");
}else if(isset($_POST['update'])){
$blogger = new Google_Service_Blogger($client);
$blog = $blogger->blogs->getByUrl(array('url'=>'<blogurl>'));
$mypost = new Google_Service_Blogger_Post();
$mypost->setTitle($_POST['title']);
$mypost->setContent($_POST['desc']);
$blogger->posts->update($blog->getId(), $_GET['postid'], $mypost);
header("Location: bloglist.php");
}else if(isset($_GET['edit']) && isset($_GET['postid'])){
$blogger = new Google_Service_Blogger($client);
$blog = $blogger->blogs->getByUrl(array('url'=>'<blogurl>'));
$singlepost = $blogger->posts->get($blog->getId(), $_GET['postid']);
}
?>
<form method="post">
<table>
<tr>
<td>Title</td>
<td>
<input type="text" name="title" value="<?php echo isset($singlepost->title) ? $singlepost->title : ''; ?>">
<?php if(isset($singlepost->id)){ ?>
<input type="hidden" name="postid" value="<?php echo $singlepost->id; ?>">
<?php } ?>
</td>
</tr>
<tr>
<td>Description</td>
<td><textarea name="desc"><?php echo isset($singlepost->content) ? $singlepost->content : ''; ?></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="<?php $val = isset($singlepost->id) ? 'update' : 'submit' ; echo $val; ?>" value="<?php echo $val ; ?>"></td>
</tr>
</table>
</form>
error_reporting(E_ALL);
ini_set('display_errors',1);
session_start();
require_once dirname(__FILE__) . '/GoogleClientApi/src/Google/autoload.php';
require_once dirname(__FILE__).'/GoogleClientApi/src/Google/Client.php';
require_once dirname(__FILE__).'/GoogleClientApi/src/Google/Service.php';
require_once dirname(__FILE__).'/GoogleClientApi/src/Google/Model.php';
require_once dirname(__FILE__).'/GoogleClientApi/src/Google/Collection.php';
require_once dirname(__FILE__).'/GoogleClientApi/src/Google/Config.php';
require_once dirname(__FILE__).'/GoogleClientApi/src/Google/Service/Resource.php';
require_once dirname(__FILE__).'/GoogleClientApi/src/Google/Service/Blogger.php';
//echo '<pre>';
$scriptUri = "<redirect url>";
$client = new Google_Client();
$client->setAccessType('online'); // default: offline
$client->setApplicationName('<appName>'); //name of the application
$client->setClientId('<clientID>'); //insert your client id
$client->setClientSecret('<clientsecret>'); //insert your client secret
$client->setRedirectUri($scriptUri); //redirects to same url
$client->setDeveloperKey('<developerkey>'); // API key (at bottom of page)
$client->setScopes(array('https://www.googleapis.com/auth/blogger')); //since we are going to use blogger services
if (isset($_GET['logout'])) { // logout: destroy token
unset($_SESSION['token']);
header("Location: ".$scriptUri);
}
if (isset($_GET['code'])) { // we received the positive auth callback, get the token and store it in session
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header("Location: bloglist.php");
}
if (isset($_SESSION['token'])) { // extract token from session and configure client
$token = $_SESSION['token'];
$client->setAccessToken($token);
}
if (!$client->getAccessToken()) { // auth call to google
$authUrl = $client->createAuthUrl();
header("Location: ".$authUrl);
//die;
}
if(isset($_POST['submit'])){
$blogger = new Google_Service_Blogger($client);
//you can get the data about the blog by getByUrl
$blog = $blogger->blogs->getByUrl(array('url'=>'<blogurl>'));
//creates a post object
$mypost = new Google_Service_Blogger_Post();
$mypost->setTitle($_POST['title']);
$mypost->setContent($_POST['desc']);
//echo $blog->getId();
$data = $blogger->posts->insert($blog->getId(), $mypost);
header("Location: bloglist.php");
}else if(isset($_GET['delete']) && isset($_GET['postid'])){
$blogger = new Google_Service_Blogger($client);
$blog = $blogger->blogs->getByUrl(array('url'=>'<blogurl>'));
$data = $blogger->posts->delete($blog->getId(), $_GET['postid']);
header("Location: bloglist.php");
}else if(isset($_POST['update'])){
$blogger = new Google_Service_Blogger($client);
$blog = $blogger->blogs->getByUrl(array('url'=>'<blogurl>'));
$mypost = new Google_Service_Blogger_Post();
$mypost->setTitle($_POST['title']);
$mypost->setContent($_POST['desc']);
$blogger->posts->update($blog->getId(), $_GET['postid'], $mypost);
header("Location: bloglist.php");
}else if(isset($_GET['edit']) && isset($_GET['postid'])){
$blogger = new Google_Service_Blogger($client);
$blog = $blogger->blogs->getByUrl(array('url'=>'<blogurl>'));
$singlepost = $blogger->posts->get($blog->getId(), $_GET['postid']);
}
?>
<form method="post">
<table>
<tr>
<td>Title</td>
<td>
<input type="text" name="title" value="<?php echo isset($singlepost->title) ? $singlepost->title : ''; ?>">
<?php if(isset($singlepost->id)){ ?>
<input type="hidden" name="postid" value="<?php echo $singlepost->id; ?>">
<?php } ?>
</td>
</tr>
<tr>
<td>Description</td>
<td><textarea name="desc"><?php echo isset($singlepost->content) ? $singlepost->content : ''; ?></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="<?php $val = isset($singlepost->id) ? 'update' : 'submit' ; echo $val; ?>" value="<?php echo $val ; ?>"></td>
</tr>
</table>
</form>
thanks
ReplyDeleteGood Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging...
ReplyDeletePHP developers in chennai | PHP developers in India
ReplyDeleteThanks for sharing this niche useful informative post to our knowledge.
brochure designers in chennai | brochure design company in chennai
Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
ReplyDeleteBest Python training Institute in chennai
A debt of gratitude is in order for your educational post!!! Subsequent to finishing my graduation, I am confounded whether to pick website composition as my profession. Your article helped me to settle on a correct decision.
ReplyDeleteMBA Talks | Article Submission sites
I think this was one of the most interesting content I have read today. Please keep posting.
ReplyDeletePHP Training in Chennai
PHP Course in Chennai
I think this is the best article today about the future technology. Thanks for taking your own time to discuss this topic, I feel happy about that curiosity has increased to learn more about this topic. Keep sharing your information regularly for my future reference.
ReplyDeletejava training center in chennai
java institutes in chennai
Thanks
ReplyDeleteGoogle account. I look forward to fresh updates and will talk about this blog with my Facebook group. Chat soon!
ReplyDeletefire and safety course in chennai
It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.
ReplyDeletelinux Training in Chennai | Best linux Training Institute in Chennai
Unix Training in Chennai | Best Unix Training Institute in Chennai
Sql Training in Chennai | Best Sql Training Institute in Chennai
Oracle Training in Chennai | Best Oracle Training Institute in Chennai
Digital Marketing Training in Chennai | Best Digital Marketing Training Institute in Chennai
Awesome tips, thank you very much! I will be sharing and recommending this post to my blogging friends.Magento ecommerce
ReplyDeletedata extraction services
PHP Development Services in Chennai
Big data development company in Chennai
This comment has been removed by the author.
ReplyDeletevisit my blog WMI
ReplyDeleteThank for the post bro, it helped me a lot. Can you show me the bloglist.php file too?
ReplyDeleteVery informative post and minimal design. We do provide minimal designs and web development services. Checkout for In budget IT services:
ReplyDeleteWeb Development | WordPress Development | Web Design | Digital Marketing | Portfolio
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteGreat post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well. great work
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
ReplyDeleteoracle training in chennai
oracle training in velachery
oracle dba training in chennai
oracle dba training in velachery
ccna training in chennai
ccna training in velachery
seo training in chennai
seo training in velachery
Thanks for sharing such valuable information to us, really informative. keep going expecting for from you.
ReplyDeleteRegards..
Dinesh
PHP Training in chennai
To be honest, I don’t know how you manage to do such a good job every single time. Very well done!
ReplyDeletephp development company
I went through your blog and it’s totally awesome.this was very for me .
ReplyDeleteGreat Post. Very informative. Keep Sharing!!
ReplyDeleteApply Now for PHP Training Classes in Noida
For more details about the course fee, duration, classes, certification, and placement call our expert at 70-70-90-50-90