Bloviate is a collection of servlets running on Google App Engine that automatically posts to Blogger.
The bot includes a servlet called by a cron job, which automatically posts to a blog hosted by Blogger by using the Blogger API.
In addition, the main servlet displays a form and handles the authentication through OAuth for first-time use.
BloviateServlet when first run will authenticate the user by first collecting the Blog ID, OAuth Client ID and OAuth CLient secret, and then start the authentication process.
After authenticating with Google and granting access to the app, it will start posting.
When you visit BloviateServlet after authentication using the OAuth process, the servlet will simply display a confirmation that authentication worked, and allow a post to be created on demand.
This bot was written with the original intent that the posts would show up on Twitter, using IFTTT to copy the content which was posted to the blog to a connected Twitter account.
Additionally, the posts were generated by selecting and add a Twitter handle using a “reservoir sampling” algorithm from a file which contained a list of Twitter handles to the blog post, followed by some text content retrieved from Wordnik.
However, since this bot was first created, the service on IFTTT which would copy the content of the blog post to Twitter now requires a paid plan to use (probably to reflect the need for Twitter API access), and the Knicker library to access Wordnik for the creation of a random post no longer works.
Furthermore, the original logic heavily relied on static files to hold the Blogger ID, OAuth keys, and Twitter handles—items which are not static by nature and subject to change.
The improvements to the architecture of the bot revolve around moving the business logic out of the servlet classes, which now act more like controllers, into a service file which contains the majority of the helper functions.
The code now relies on Maven for the dependencies, and the deployment to App Engine Standard environment.
For more improvements and the changelog see the wiki.
-
Create a blog on Blogger that Bloviate will post to.
- Go to https://www.blogger.com/dashboard/ and click "Create a blog".
- Log into your Google account
- Choose a Title and a URL for the blog
- Click Create
- Take note of the Blog ID—it's the 19 digit number that appears after the blogger.com URL.
-
Create a Google App Engine application for Bloviate.
- Go to https://console.cloud.google.com/appengine and click "Create project"
- Name the project "Bloviate" (mandatory)
- Take note of the project ID—it's generated automatically.
-
Create an OAuth Client ID and Secret so that Bloviate can authenticate and post to Blogger.
- Go to https://console.developers.google.com/apis/
- Select the "Bloviate" project.
- Click on Credentials in the left menu
- Click Create credentials and choose OAuth Client ID
- Configure the Google Auth Platform and choose External consent.
- Under Application type, select Web application.
- Name the application Bloviate.
- Under Authorized redirect URIs, input your redirect URI here. For now you can just set it to http://localhost:8080/oauth2callback but later you must use the actual callback URL that the app will use when uploaded to the Google App Engine.
- Click Create
- Take note of the Client ID and Client Secret.
-
Add a test user to your OAuth application.
- Go to https://console.cloud.google.com/auth/audience and choose your project
- Under Test users, click Add users
- Add your Google account e-mail and click save.
-
Enable the Blogger API so Bloviate can post.
- Go to https://console.developers.google.com/apis/api/blogger.googleapis.com/
- Click Enable
-
Test Bloviate on your local server.
- From the project root, run
mvn package appengine:run - Visit http://localhost:8080/ to test that Bloviate works.
- From the project root, run
-
Deploy Bloviate to Google App Engine.
- Run
gcloud auth loginand log in with your Google account. - Run
gcloud config set project [YOUR_PROJECT_ID]replacing the placeholder with your Google App Engine project ID for Bloviate that you noted earlier. - Run
gcloud app create --region=us-central --project [YOUR_PROJECT_ID]again using the placeholder value. - Run
gcloud services enable cloudscheduler.googleapis.com pubsub.googleapis.comso that Bloviate can run the cron jobs. - Deploy to GAE using
mvn package appengine:deploy. Take note of your cloud app URL which ends in appspot.com.
- Run
-
Configure the new callback URL.
- Go to https://console.cloud.google.com/apis/credentials, find Bloviate under OAuth 2.0 Client IDs inside your project, and click the pencil icon to edit.
- Under Authorized redirect URIs click +Add URI
- Add your callback URL (the URL noted in step 7.iv) followed by
oauth2callback. - Press save.
For more Google commands see the wiki.
For first-time users The BloviateServlet displays a form which accepts the Blog ID (previously in the properties file) as well as the OAuth keys (also previously located inside a file). These keys are stored in the Datastore.
You can set the frequency of the posting to the blog in the cron.xml file.