Posted inGoogle

Auto Post On Blogspot Using PHP script

Auto Post On Blogspot Using PHP script

Today, We want to share with you Auto Post On Blogspot Using PHP script.
In this post we will show you Automatically Post Content To Blogspot Using PHP, hear for Automatically post to a Blogspot page using the Blogspot PHP API we will give you demo and example for implement.
In this post, we will learn about Automatically Post Content To Blogspot Using PHP with an example.

How to Auto Post on Blogspot with PHP Example

This Offical document Learn how to get step by step How to Auto Post on Blogspot with PHP started using the Blogger API.Blogger API

//Dynemic generate return URL
$redirct_url = "https://".$_SERVER["HTTP_HOST"].$_SERVER['PHP_SELF'];
//include all libs using google
require_once 'google-api-php-client-master/src/Google/autoload.php'; 

$google_clnt = new Google_Client();
$google_clnt->setApplicationName("PakaInfo");
$google_clnt->setDeveloperKey("Ahdjhjdfid554dDDDkjkjkk52-25sdjs20dddKsjhdd5");

$google_clnt->setAccessType('online');
$google_clnt->setClientId("988995555356-9898kasjdjdibmi55ss1bk94plhu58Dioene.apps.googleusercontent.com");
$google_clnt->setClientSecret("82cVvhOy5z3hsW2Ur4fgdfg8QXaBR");
$google_clnt->setRedirectUri($redirct_url);
$google_clnt->setScopes(array('https://www.googleapis.com/auth/blogger')); //since we are going to use blogger services

$bloggerService = new Google_Service_Blogger($google_clnt);

if (isset($_GET['logout'])) { // Google logout: Your destroy token
unset($_SESSION['token']);
 die('Good Luck Logged out.');
}

if (isset($_GET['code'])) { // we get the positive google auth callback, get the simple google auth token and some store it in session
	$google_clnt->authenticate($_GET['code']);
	$_SESSION['token'] = $google_clnt->getAccessToken();
}

if (isset($_SESSION['token'])) { // extract get token from session and configure google_clnt
	$get_token = $_SESSION['token'];
	$google_clnt->setAccessToken($get_token);
}

if (!$google_clnt->getAccessToken()) { // Your auth call to google
	$authUrl = $google_clnt->createAuthUrl();
	header("Location: ".$authUrl);
	die;
}

$posts = $bloggerService->posts;

$LivePost = new Google_Service_Blogger_Post();
$LivePost->setTitle("WRITE_YOUR_POST_TITLE ".time());
$LivePost->setLabels("WRITE_YOUR_POST_LABEL");
$LivePost->setContent("WRITE_YOUR_POST_CONTENT!!!!");
$LivePost->setCustomMetaData("YOUR_CUSTOM_META_DATA ".time());

try
{
	$nposts = $posts->insert("4842995321113595808",$LivePost);
}
catch(Exception $e)
{
	//generate Error
   print_r($e);
}
	

Auto Post to Blogger with Title , post label and search some description using Blogger PHP Script API v 3.0

And then this post, After that We logged into blogger on Google Product. I can display the above post title and description there. With this auto post has successfully upload ‘Post Title’ as well as ‘Post Body’.

Adding a post : Auto Post On Blogspot Using PHP

We can Simple Add an Auto post for a google product blog by sending a POST All the data request to the using post Methods collection URL with a post Simple JSON body:

https://www.googleapis.com/blogger/v3/blogs/blogId/posts/

Auto Post On Blogspot Using PHP : Request

POST https://www.googleapis.com/blogger/v3/blogs/4842995321113595808/posts/
Authorization: /* get here Google OAuth 2.0 token here */
Content-Type: application/json

{
  "kind": "blogger#post",
  "blog": {
    "id": "4842995321113595808"
  },
  "title": "My First Auto Post On Blogspot Using PHP Example ",
  "content": "Welcome 

pakainfo.com

You Are Always Welcome..." }

We must be Google authenticated to Add a Auto post on The Google Blogger.

Auto post into Blogspot using php code

Auto-posting into Blogspot using PHP code can be achieved using the Blogger API, which provides a set of methods to interact with the Blogger platform. Here’s an example of how to use PHP code to auto-post into Blogspot:

First, you need to obtain an API key from the Google Developer Console. Follow these steps to get an API key:

Go to the Google Developer Console and create a new project.
Navigate to the Credentials section and create a new API key.
Note down the API key for later use.

Next, you need to authenticate your application with the Blogger API. Here’s an example of how to do that using the Google API client library for PHP:

require_once 'vendor/autoload.php';

$client = new Google_Client();
$client->setApplicationName('My Blogger App');
$client->setDeveloperKey('YOUR_API_KEY_HERE');
$service = new Google_Service_Blogger($client);

Once you have authenticated your application, you can use the Blogger API to create a new blog post. Here’s an example of how to do that:

$post = new Google_Service_Blogger_Post();
$post->setTitle('My First Blog Post');
$post->setContent('This is my first blog post. Hello world!');

$blogId = 'YOUR_BLOG_ID_HERE';
$service->posts->insert($blogId, $post);

In the above code, replace YOUR_API_KEY_HERE with your API key, and YOUR_BLOG_ID_HERE with the ID of your Blogspot blog.

Finally, you can run the PHP code to auto-post into Blogspot. You can either run the code manually, or set up a cron job to run the code automatically at specified intervals.

Note that the above code is just an example, and you may need to modify it to suit your specific needs. Additionally, make sure to follow the Blogger API usage limits and guidelines to avoid any issues.

We hope you get an idea about Auto post into Blogspot using php Source code
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.

We hope This Post can help you…….Good Luck!.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype