Linux.com

Home Learn Linux Linux Tutorials Manage Google Services from the Command Line on Linux

Manage Google Services from the Command Line on Linux

 

I love Web services. I'm just not a fan of always having to use a browser as the interface for said services. Google's services have crept into my daily routine to the point that I'm using Gmail, Google Calendar, and Google Docs all the time. But I also like doing things from the command line, which is why I'm using GoogleCL to connect to Google services from the command line.

GoogleCL is a set of Python scripts that use the GData Python bindings to connect to Google services. So you authenticate to your Google account, and then you can pull or push data to a set of Google services. The GoogleCL suite only uses Google APIs, so it's a bit constrained by what Google actually allows via the API — there's no screen-scraping or hackery going on that would let GoogleCL do something that's not allowed by the API.

GoogleCL supports Google Docs, Picasa, Blogger, Google Calendar, Google Contacts, and YouTube. If you're wondering why it doesn't support Gmail, just remember that you can already interact with Gmail services via POP3, IMAP, and SMTP — so you can already set up text-based mailers and CLI tools to work with Gmail if you like.

Getting Started with GoogleCL

The GoogleCL tools are offered as source, generic Debian packages, and also as Windows packages. The Debian package installs just fine on Ubuntu 10.04 and Linux Mint 9. Note that the packaged downloads are not always the latest version and sometimes the Debian packages are older or newer than Windows, etc.

You're going to need Python 2.5 or 2.6, and the gdata Python client. The install instructions are pretty clear, so I won't repeat them here. If you're using a distro that's a few years old, you may have some trouble with the Python dependencies — but if you're using a distro from the last year or so you should be fine.

You can run GoogleCL in a couple ways. Run google and you'll get a shell prompt like >. From the prompt you can access services by using the name of the service and then the commands. For instance, if I want a list of my docs:

docs list

Will provide a list of documents at the top level. To retrieve a document, you'd use docs get and then specify the folder and/or title of the document.

If it's the first time that you've used GoogleCL, you'll be prompted to go to a URL and authorize the system. This is why you didn't have to set up a config file ahead of time to use GoogleCL — it'll set everything up the first time. Note that each service has to be authorized independently. If you've already set up the Docs account, you still have to set up the Contacts account, or Picasa, or Blogger.

One of my favorite uses is to add an item to my calendar. From the GoogleCL prompt, run:

calendar add "6pm today appointment for myself"

And Google will add an entry reminding you that you have a task at 6 p.m. Want to see the list of calendar events? Use calendar list and you'll get the tasks you've added to the calendar with the text first, and then the time that it's due. This can be a handy way of keeping a calendar without ever having to enter the browser.

Want to add an entry from the command line without going to the GoogleCL prompt? Do it this way:

google calendar add "My thing today at 7pm"

You can also use the GoogleCL to upload pictures in bulk to Picasa and upload videos to YouTube and posts to Blogger if you use those services. I'm still a Flickr fan, myself — and would love a CLI tool for Flickr if there is one.

If you're a Blogger blogger, you can write your posts in whatever editor you prefer, then upload the entry to Blogger without having to touch the browser. For instance, you can post a text file as a blog entry using:

blogger post --tags "NewPost,GoogleCL" --title "Using GoogleCL" post.txt --draft

The --draft does just what you'd expect — sets the post as a draft until you eyeball it.

These are just simple examples, you can find some really nifty stuff in the example scripts on Google's site. With a little help from GoogleCL, you could easily whip up some shell scripts to interact with Google services and remove the browser from the equation when it comes to uploading videos or blog posts.

If you want to easily switch accounts or deauthorize access for GoogleCL, go to your Google Account Settings page and look for the authorized applications. You can revoke access there, and then sign in to a new account or just use it to revoke access. Note that it may take a short while for GoogleCL to show up in the list, but no more than three hours according to the GoogleCL FAQ.

Using GoogleCL you can upload and download documents, pictures, videos, and blog posts, and manage your contacts and calendar. I've just scraped the surface here, but if you're looking for a CLI interface to manage some of your data in Google's "cloud," GoogleCL is the way to go. Found an interesting use for GoogleCL? Let us know in the comments!

 

Comments

Subscribe to Comments Feed

Upcoming Linux Foundation Courses

  1. LFS230 Linux Network Management
    06 Oct » 09 Oct - Virtual
    Details
  2. LFS416 Linux Security
    06 Oct » 09 Oct - Washington
    Details
  3. LFD331 Developing Linux Device Drivers
    13 Oct » 17 Oct - Virtual
    Details

View All Upcoming Courses

Become an Individual Member
Check out the Friday Funnies

Sign Up For the Linux.com Newsletter


Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board