コマンドラインでGoogleサービスデータにアクセスする


Command line tools for the Google Data APIs
http://code.google.com/p/googlecl/


インストールして、まずはやみくもにサンプルコマンドを叩く。

~$ google calendar list --date 2010-06-01,2010-06-30
Did not find config / preferences file at /home/unagi/.googlecl/config
... making new one.
Please specify user: ubagi_brandnew
(Hint: You can automatically launch your browser by adding "auth_browser = <browser>" to your config file under the GENERAL section, or define the BROWSER environment variable.)
Please log in and/or grant access via your browser at https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=4%2aGTA3YHWaaBagxzAb2RFPtxOrRdFW then hit enter.
Token upgrade failed! Could not get OAuth access token.
Failed to get valid access token!

表示されたURLにブラウザでアクセス。

外部アクセスを許可して、コンソールに戻りENTER。


トークンファイルが作成されている。

~$ ls .googlecl/
access_tok_unagibrandnew  config


再度、コマンドを叩く

~$ google calendar list --date 2010-06-01,2010-06-30
焼肉の会,http://www.google.com/calendar/event?eid=MTZ0bHNxMWZjbGlrOTJv2Y3UzdjJtNmsgY2F0Y2hpZXMwMEBob3RtYWlsLmNvbQ
東京出張,http://www.google.com/calendar/event?eid=OGpxdTc3YjR0MnM0MXXRiMWp2dDZxaWMgY2F0Y2hpZXMwMEBob3RtYWlsLmNvbQ
アウトレイジ,http://www.google.com/calendar/event?eid=ZWprb2owOTkzcmtnaGGNqNzdydmZubjAgY2F0Y2hpZXMwMEBob3RtYWlsLmNvbQ


いろんなことできるみたい。

~$ google -h
Usage: google [picasa|blogger|youtube|docs|contacts|calendar] TASK [options]

This program provides command-line access to (some) google services via their gdata APIs.
Called without a service name, it starts an interactive session.

Available tasks for service picasa: 'get', 'create', 'list', 'list-albums', 'tag', 'post', 'delete'
 get: Download photos
  Requires: none Optional: title, query Arguments: LOCATION

 create: Create an album
  Requires: title Optional: date, summary, tags Arguments: PATH_TO_PHOTOS

 list: List photos
  Requires: delimiter Optional: title, query

 list-albums: List albums
  Requires: delimiter Optional: title

 tag: Tag photos
  Requires: tags AND (title OR query)

 post: Post photos to an album
  Requires: title Optional: tags Arguments: PATH_TO_PHOTOS

 delete: Delete photos or albums
  Requires: (title OR query)


Available tasks for service blogger: 'post', 'tag', 'list', 'delete'
 post: Post content.
  Requires: none Optional: blog, title, tags Arguments: PATH_TO_CONTENT or CONTENT

 tag: Label posts
  Requires: tags AND title Optional: blog

 list: List posts in your blog
  Requires: delimiter Optional: blog, title

 delete: Delete a post.
  Requires: title Optional: blog


Available tasks for service youtube: 'post', 'tag', 'list', 'delete'
 post: Post a video.
  Requires: category AND devkey Optional: title, summary, tags Arguments: PATH_TO_VIDEO

 tag: Add tags to a video and/or change its category.
  Requires: devkey AND title AND (category OR tags)

 list: List videos by user.
  Requires: delimiter Optional: title

 delete: Delete videos.
  Requires: devkey Optional: title


Available tasks for service docs: 'edit', 'delete', 'list', 'upload', 'get'
 edit: Edit a document
  Requires: title Optional: format, editor

 delete: Delete documents
  Requires: none Optional: title

 list: List documents
  Requires: delimiter Optional: title, folder

 upload: Upload a document
  Requires: none Optional: title, folder, no-convert Arguments: PATH_TO_FILE

 get: Download a document
  Requires: (title OR folder) Arguments: LOCATION


Available tasks for service contacts: 'add', 'list', 'delete'
 add: Add contacts
  Requires: none Arguments: CONTACT DATA or CSV FILE

 list: List contacts
  Requires: delimiter Optional: title

 delete: Delete contacts
  Requires: none Optional: title


Available tasks for service calendar: 'add', 'list', 'today', 'delete'
 add: Add event to a calendar
  Requires: none Optional: cal Arguments: QUICK_ADD_TEXT

 list: List events on a calendar
  Requires: delimiter Optional: title, query, date, cal

 today: List events for the next 24 hours
  Requires: delimiter Optional: title, query, cal

 delete: Delete event from a calendar
  Requires: (title OR query) Optional: date, cal




Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  --blog=BLOG           Blogger only - specify a blog other than your primary.
  --cal=CAL             Calendar only - specify a calendar other than your
                        primary.
  -c CATEGORY, --category=CATEGORY
                        YouTube only - specify video categories as a comma-
                        separated list, e.g. "Film, Travel"
  --config=CONFIG       Specify location of config file.
  --devtags=DEVTAGS     YouTube only - specify developer tags as a comma-
                        separated list.
  --devkey=DEVKEY       YouTube only - specify a developer key
  -d DATE, --date=DATE  Date in YYYY-MM-DD format. Picasa only - sets the date
                        of the album  Calendar only - date of the event to add
                        / look for.        Can also specify a range via YYYY-
                        MM-DD,YYYY-MM-DD
  --delimiter=DELIMITER
                        Specify a delimiter for the output of the list task.
  --draft               Blogger only - post as a draft
  --editor=EDITOR       Docs only - editor to use on a file.
  -f FOLDER, --folder=FOLDER
                        Docs only - specify folder(s) to upload to / search
                        in.
  --format=FORMAT       Docs only - format to download documents as.
  -n TITLE, --title=TITLE
                        Title of the item
  --no-convert          Google Apps Premier only - do not convert the file on
                        upload. (Else converts to native Google Docs format)
  -q QUERY, --query=QUERY
                        Full text query string for specifying items. Searches
                        on titles, captions, and tags.
  -s SUMMARY, --summary=SUMMARY
                        Description of the upload, or file containing the
                        description.
  -t TAGS, --tags=TAGS  Tags for item, e.g. "Sunsets, Earth Day"
  -u USER, --user=USER  Username to use for the task. Exact application is
                        task-dependent. If authentication is necessary, this
                        will force the user to specify a password through a
                        command line prompt or option.


マルチなアカウントの使用と、マルチなコマンドオプションで、めんどくさくなる。
まあ、コマンドラインからアクセスできるのはいいことだと。