ラベル Google Calendar の投稿を表示しています。 すべての投稿を表示
ラベル Google Calendar の投稿を表示しています。 すべての投稿を表示

2012年6月24日日曜日

Sync Vim with Google Calendar(3/3)

Setting of viske.vim

Next, you can modify your .vimrc to activate Google Calendar Pulgin.

If you installed viske.vim by Bundle, you should check the path of "gcal.rb" first. Please place the script at a below location.

$VIMHOME/ruby/gcal.rb

Then add below settings to .vim.rc so as to activate sync plugin. Please substitute your own value for {CALENDAR-ID}.

let g:viskeGcalId = "{CALENDAR-ID}" 
cal viske#setSyncFunc("viske#gcal")

{CALENDAR-ID} might be the same as a google account. You can check an actual Calendar-ID at a setting of Google Calendar.

Now you can synchronize viske schedule with Google Calendar. Congratulation!!

Parameters

You can modify the behavior of this scripts by below parameters.

Parameter nameDescriptionexample
g:viskeGcalIDCalencar ID to be synchronizedvimyum@gmail.com
g:viskeGcalGetScriptPath to gcal.rb$HOME . ".vim/ruby/gcal.rb"
g:viskeGcalTZoneTime zone"+0900"
g:viskeGcalAuthFilePath to AOuth token$HOME . ".google-api.yaml"
g:viskeSyncNoConfIf it exists, viske does not confirm before synchronizing."true"
g:viskeSyncReadOnlyIf it exists, viske does not apply local change to Google calendar."true"

Caution

This script may contain a lot of bugs. It can damage your data on google calendar by unexpected behavior. Pleas kindly use these scripts at your own risk.

Sync Vim with Google Calendar(1/3)

Get Client-ID、Client-Secret

Client-ID and Client-Secret are required to use Google Calendar API v3, . Let's start with accessing the Google API Console with your Google account. You might see a below image. Click the "Create Project...".

On next screen, click a toggle buttom next to "Calendar API". If you can not see the button, please check the "Services" is selected on side menu.

Proceed the confirmation with clicking "accept" twice. Finishing activation, you can see the below image.

Next, click the "API Access" on the left side menu.

You can see the "Create an OAuth 2.0 Client ID...", and click it.

You can input a product name of your choice, and click "Next".

Choose "Installed application" as "Application type". Then click "Create Client ID".

You got the "Client ID" and "Client Secret" on the following screen.

These values are required to get OAuth token on next step. Let's memorize it.

Get OAuth token

next step.

Sync Vim with Google Calendar(2/3)

Install libraries

You can install required libraries to access the Google API with RubyGems. If you have not installed RubyGems, you should install RubyGems first.

sudo aptitude install rubygems

Now you can install libraries with RubyGems as below.

sudo gem install google-api-client
sudo gem install --remote sinatra httpadapter extlib dm-sqlite-adapter

Get OAuth Token

Let's obtain an OAuth token using "Client ID" and "Client Secret" . Input below command. Please substitute your own values for {CLIENT-ID} and {CLIENT-SECRET}.

/var/lib/gems/1.8/bin/google-api oauth-2-login \
  --scope=https://www.googleapis.com/auth/calendar \
  --client-id={CLENT-ID} \
  --client-secret={CLIENT-SECRET}

Path of google-api is changed according to your environment. My mac environment, the path is a below one.

/Library/Ruby/Gems/1.8/gems/google-api-client-0.4.4/bin/google-api

Once you input the abobe command, a web browser will be launched and requires an acceptance. If you can accept, let give it an access authority.

After you accept the request, New OAuth token file ".google-aip.yaml" would be created in your home directory.

Setting of vise.vim

next step

2012年6月22日金曜日

Googleカレンダーと同期させる(3/3)

viske.vimをGoogleカレンダーと同期させる(3/3)

viske.vimの設定

OAuthのトークンを取得したら、Googleカレンダー同期プラグインを有効にするだけです。OAuthトークンの取得がまだの場合はこちらの記事を参照してください。

Googleカレンダーとの同期プラグインはviske.vimのパッケージに同梱しています。下記の2つのファイルがGoogleカレンダー同期用のファイルです。Bundleなどでインストールした場合は、gcal.rbの場所が異なります。下記の位置にコピーしてください。

$VIMHOME/ruby/gcal.rb
$VIMHOME/autoload/viske/gcal.vim

同期機能を有効にするには、設定ファイル(.vimrc)に下記を追加します。

let g:viskeGcalId = "カレンダーID" 
cal viske#setSyncFunc("viske#gcal")

カレンダーIDは一般的にはGoogleアカウントです。Googleカレンダーにログインして、設定から確認できます。

設定

その他、Googleカレンダー同期プラグインには、下記の設定が可能です。

パラメータ内容設定例
g:viskeGcalID同期するカレンダーのIDvimyum@gmail.com
g:viskeGcalID同期するカレンダーのIDvimyum@gmail.com
g:viskeGcalGetScriptgcal.rbのパス$HOME . ".vim/ruby/gcal.rb"
g:viskeGcalTZoneタイムゾーン"+0900"
g:viskeGcalAuthFileOAuthトークンのパス$HOME . ".google-api.yaml"
g:viskeSyncNoConf同期時に確認しない"true"
g:viskeSyncReadOnlyVimの変更をGoogleカレンダーに反映しない"true"

注意事項

本スクリプトは素人が試行錯誤して作ったもののため、多分にバグを含んでいます。もしかすると、意図しない挙動によりあなたの大事なGoogleカレンダー上のスケジュールを破壊してしまうかもしれません。ご使用の場合は十重にご承知置きください。

Googleカレンダーとの同期(2/3)

viske.vimをGoogleカレンダーと同期させる(2/3)

ライブラリのインストール

Google CalendarのクライアントIDとクライアントシークレットを取得したら、次はライブラリのインストールです。まだ取得していない場合は前回の記事を参照してください。

Google Calendarにrubyでアクセスするために必要なライブラリはRubyGemsでインストールできます。RubyGemsをインストールしていない場合は先にRubyGemsをインストールしましょう。Ubuntuにてaptitudeでインストールする場合はこんなかんじです。

sudo aptitude install rubygems

Windowsにインストールする場合は、下記のサイトあたりがわかりやすいと思います。

Num.b:Windows に Ruby と RubyGems を入れる

RubyGemsをインストールしたら、RubyGemsを使って必要なライブラリをインストールします。

sudo gem install google-api-client
sudo gem install --remote sinatra httpadapter extlib dm-sqlite-adapter

OAuthトークンの取得

前回取得したクライアントIDとクライアントシークレットを使ってOAuthのトークンを取得します。

/var/lib/gems/1.8/bin/google-api oauth-2-login \
  --scope=https://www.googleapis.com/auth/calendar \
  --client-id=クライアントID \
  --client-secret=クライアントシークレット

google-apiコマンドのパスは環境によって異なります。Macでは下記のパスにインストールされました。

/Library/Ruby/Gems/1.8/gems/google-api-client-0.4.4/bin/google-api

上のコマンドが成功すれば、Webブラウザが起動し、認証を求める下のような画面が表示されます。問題が無ければ、アクセスを許可しましょう。

成功すれば、ホームディレクトリ以下に".google-aip.yaml"というファイルができているはずです。以降、このファイルをOAuthトークンと呼びます。

viske.vimの設定

次の記事に続きます。

Googleカレンダーとの同期(1/3)

viske.vimをGoogleカレンダーと同期させる(1/3)

Client ID、Client Secreの取得

同期させるにはGoogle APIを使用するため、同期させるカレンダーについてClient ID, Client Secretというものが必要になります。まずはGoogle API Consoleにアクセスします。はじめての場合、下のような画面が出るはずです。真ん中の"Create Project..."をクリックしましょう。

画面が変わるので、Calendar APIの横のスライドバーをしましょう。画面が異なる場合は左端のメニューで"Services"になっているか確認してください。

同意確認が2回でてくるので、内容を確認して"accept"を押します。下記の画面のようにCalendar APIのスライドバーが"ON"になればOKです。

次に、画面左のメニューから"API Access"を選んでください

切り替わった画面の真ん中にある"Create an OAuth 2.0 Client ID..."をクリックします。

"product name"を適当に入力して、"next"をクリックします。

"Application type"は"Installed application"を選択して、"Create Client ID"をクリックします。

切り替わった下記の画面に表示されているのが、それぞれ"Client ID"と"Client Secret"になります。

これらの値は同期において必要となるため、どこかにメモしておきましょう

OAuthのトークンを取得する

次の記事に続きます。