Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Bloviate — A bot running on GAE that posts to Blogger

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.

Workflow

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.

Origins of Bloviate

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.

Improvements to the original Bloviate

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.

Setting Up Bloviate

  1. Create a blog on Blogger that Bloviate will post to.

    1. Go to https://www.blogger.com/dashboard/ and click "Create a blog".
    2. Log into your Google account
    3. Choose a Title and a URL for the blog
    4. Click Create
    5. Take note of the Blog ID—it's the 19 digit number that appears after the blogger.com URL.
  2. Create a Google App Engine application for Bloviate.

    1. Go to https://console.cloud.google.com/appengine and click "Create project"
    2. Name the project "Bloviate" (mandatory)
    3. Take note of the project ID—it's generated automatically.
  3. Create an OAuth Client ID and Secret so that Bloviate can authenticate and post to Blogger.

    1. Go to https://console.developers.google.com/apis/
    2. Select the "Bloviate" project.
    3. Click on Credentials in the left menu
    4. Click Create credentials and choose OAuth Client ID
    5. Configure the Google Auth Platform and choose External consent.
    6. Under Application type, select Web application.
    7. Name the application Bloviate.
    8. 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.
    9. Click Create
    10. Take note of the Client ID and Client Secret.
  4. Add a test user to your OAuth application.

    1. Go to https://console.cloud.google.com/auth/audience and choose your project
    2. Under Test users, click Add users
    3. Add your Google account e-mail and click save.
  5. Enable the Blogger API so Bloviate can post.

    1. Go to https://console.developers.google.com/apis/api/blogger.googleapis.com/
    2. Click Enable
  6. Test Bloviate on your local server.

    1. From the project root, run mvn package appengine:run
    2. Visit http://localhost:8080/ to test that Bloviate works.
  7. Deploy Bloviate to Google App Engine.

    1. Run gcloud auth login and log in with your Google account.
    2. Run gcloud config set project [YOUR_PROJECT_ID] replacing the placeholder with your Google App Engine project ID for Bloviate that you noted earlier.
    3. Run gcloud app create --region=us-central --project [YOUR_PROJECT_ID] again using the placeholder value.
    4. Run gcloud services enable cloudscheduler.googleapis.com pubsub.googleapis.com so that Bloviate can run the cron jobs.
    5. Deploy to GAE using mvn package appengine:deploy. Take note of your cloud app URL which ends in appspot.com.
  8. Configure the new callback URL.

    1. 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.
    2. Under Authorized redirect URIs click +Add URI
    3. Add your callback URL (the URL noted in step 7.iv) followed by oauth2callback.
    4. Press save.

For more Google commands see the wiki.


Customization

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.

About

Post automatically to Blogger with a bot that runs on Google App Engine

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages