Post text/HTML files to Google Blogger using OAuth 2.0
gblog is a Python command-line tool that allows you to post content from text files (which may contain HTML) to Google Blogger blogs using OAuth 2.0 authentication.
Version: 1.4.0
- ✅ OAuth 2.0 authentication with Google
- ✅ Support for HTML content in text files
- ✅ Post directly or save as draft
- ✅ Add labels/tags to posts
- ✅ Automatic blog selection if you have multiple blogs
- ✅ Token refresh for seamless re-authentication
- ✅ Semantic versioning support
- ✅ Verbose debugging output option
- ✅ Extract title and labels from file metadata
- ✅ YAML configuration file support
- Python 3.7 or higher
- A Google account with a Blogger blog
- Google Cloud Project with Blogger API enabled
- Clone this repository:
git clone https://github.com/linuxha/gblog.git
cd gblog- Install required dependencies:
pip install -r requirements.txtBefore using gblog, you need to set up OAuth credentials:
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Blogger API v3:
- Go to "APIs & Services" > "Library"
- Search for "Blogger API v3"
- Click "Enable"
- Create OAuth 2.0 credentials:
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Choose "Desktop application" as the application type
- Give it a name (e.g., "gblog")
- Click "Create"
- Download the credentials JSON file and save it as
credentials.jsonin the gblog directory
An example template is provided in credentials.json.example.
Post a text file to your blog:
python gblog.py -f mypost.txt -t "My Blog Post Title"The script supports HTML tags in your text files:
python gblog.py -f mypost.html -t "My HTML Post"python gblog.py -f mypost.txt -t "Draft Post" --draftpython gblog.py -f mypost.txt -t "Tagged Post" --labels "python,blogging,tutorial"If you have multiple blogs, specify which one to use:
python gblog.py -f mypost.txt -t "My Post" -b https://myblog.blogspot.comFor more efficient posting, use the blog ID directly (most efficient method):
python gblog.py -f mypost.txt -t "My Post" --blog-id 1234567890123456789Note: The --blog-id option takes precedence over --blog-url if both are specified.
Finding your Blog ID: You can find your blog ID by running the script once without specifying --blog-id or --blog-url, and it will list all your blogs with their IDs. You can also find it in your blog's Blogger dashboard URL: https://www.blogger.com/blogger.g?blogID=YOUR_BLOG_ID_HERE
You can specify different token files for different Google accounts:
# Use a specific token file
python gblog.py -f mypost.txt -t "My Post" --token my_account_token.json
# Support for .js extension (treated as JSON)
python gblog.py -f mypost.txt -t "My Post" --token my_account_token.js
# Use tokens for different accounts
python gblog.py -f work_post.txt -t "Work Post" --token work_account.json
python gblog.py -f personal_post.txt -t "Personal Post" --token personal_account.jsonpython gblog.py -f mypost.txt -t "My Post" -c /path/to/credentials.jsonYou can embed metadata directly in your content files using HTML comments. This eliminates the need to specify title and labels via command line:
<!-- title>Your Blog Post Title<title -->
<!-- labels>tag1, tag2, tag3<labels -->
<h1>Your content starts here</h1>
<p>The rest of your post content...</p>Post with embedded metadata:
python gblog.py -f mypost_with_metadata.txtCommand line arguments take precedence over file metadata:
# This will use "Override Title" instead of the title in the file
python gblog.py -f mypost_with_metadata.txt -t "Override Title"Metadata format rules:
- Title format:
<!-- title>Your Title Here<title --> - Labels format:
<!-- labels>Label A, Label B, Label C<labels --> - Title cannot be empty (must provide via command line or file)
- Labels are optional and can be empty
- Whitespace around titles and labels is automatically trimmed
- Command line arguments always take precedence over file metadata
-f, --file FILE Text/HTML file to post (required)
-t, --title TITLE Post title (if not provided, will attempt to extract from file)
-b, --blog-url URL Blog URL (e.g., https://myblog.blogspot.com)
--blog-id ID Blog ID (direct specification, takes precedence over --blog-url)
-l, --labels LABELS Comma-separated list of labels/tags
--draft Create as draft instead of publishing
-c, --credentials FILE Path to credentials.json file (default: credentials.json)
--token FILE Path to token file (supports .json/.js extensions, default: token.json)
--config FILE, -C FILE Path to YAML configuration file
-v, --verbose Enable verbose output for debugging
--version Show version information and exit
--version: Display the current version of gblog and exit-v, --verbose: Enable verbose debug output to help troubleshoot issues with authentication, file reading, blog selection, and posting- Title extraction: The
-t, --titleoption is now optional if your file contains embedded title metadata - Label extraction: Labels can now be extracted from file metadata, with command line labels taking precedence
--config, -C: Load settings from YAML configuration file
Check version:
python gblog.py --versionEnable verbose debugging output:
python gblog.py -f mypost.txt -t "Debug Post" --verbosePost using only metadata from file:
python gblog.py -f post_with_metadata.txt --verboseUse different token files for multiple accounts:
python gblog.py -f work_post.txt --token work_token.json
python gblog.py -f personal_post.txt --token personal_token.jsUse configuration file with metadata extraction:
python gblog.py -f post_with_metadata.txt --config blog_config.yaml --verboseOn the first run, the script will:
- Open your web browser
- Ask you to log in to your Google account
- Request permission to access your Blogger account
- Save the authentication token to
token.jsonfor future use
The token will be automatically refreshed when needed.
Your text files can contain plain text or HTML. Here's an example:
This is a sample blog post with HTML content.
<h2>Introduction</h2>
<p>This is a paragraph with <strong>bold text</strong> and <em>italic text</em>.</p>
<h2>Features</h2>
<ul>
<li>Support for HTML tags</li>
<li>Easy to use</li>
</ul>A sample post file is included: sample_post.txt
- Keep your
credentials.jsonfile secure and never commit it to version control - The
token.jsonfile contains your access token - keep it private - Both files are already included in
.gitignore
Make sure you've downloaded the OAuth credentials from Google Cloud Console and saved them as credentials.json.
Ensure you have at least one blog on your Google account at blogger.com.
Delete token.json and run the script again to re-authenticate.
See LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.